如何在django模板中包含外部的CSS,图像等? [英] How to include external css, image, etc in django template?
问题描述
在django中,所有URL都从urls.py文件解析。所以没有这样的目录结构。
那么,如果你必须在你的模板中包含一个css文件呢? >
有没有添加到url.py文件的方法?
如果不是,那么你会新的条目每个资源的urls.py?
请参阅静态文件中的Django HOWTO 。
基本上在您的配置文件中,您指定一个特殊目录来存储静态文件。文档中的示例是:
STATIC_ROOT = /home/jacob/projects/mysite.com/sitestatic
您将CSS文件,图像,等等,并且服务器将知道提供与该目录中的静态URL模式相匹配的URL。
In django, all urls are parsed from urls.py file. So, there is no directory structure as such.
So, what if you have to include a css file in your template ?
Is there a way without adding it to url.py file ?
If no, then will you make new entry in urls.py for every resource ?
See the Django HOWTO on static files.
Basically, in your configuration file, you specify a special directory to store static files in. The example in the docs is:
STATIC_ROOT = "/home/jacob/projects/mysite.com/sitestatic"
You put CSS files, images, etc. in there, and the server will know to serve URLs that match your static URL pattern from that directory.
这篇关于如何在django模板中包含外部的CSS,图像等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!