我的Django模板使用了很多相关的东西:图像、样式表等。
我应该把这些文件放在哪里,或者我应该如何在模板本身中引用它们?
现在我使用的是开发服务器。
我知道这是一件很常见的事情,但我真的搞不懂。
发布于 2009-12-12 09:34:52
我将它们放在一个名为static的文件夹中,该文件夹位于web项目的顶层文件夹中。
示例:
/静态/img/
/static/js/
/static/css/
/模板/
urls.py
settings.py
然后,我的urls.py文件中包含以下规则:
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),我的settings.py包含:
MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'static').replace('\\', '/')
ADMIN_MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'static/admin').replace('\\', '/')发布于 2009-12-12 12:04:11
发布于 2009-12-12 13:59:28
我们把我们的放在/media下面。所有与网站布局相关的内容都被进一步分开。当然,这些静态内容都不是Django在生产站点上提供的。它们通常甚至不在同一物理服务器上。
/media
/images - this is for content-specific images
/video - these next 2 are normally symlinks to a /big_content folder ...
/audio - so that they aren't included in our mercurial repository.
/layout - everything that is tied to the basic templates.
/css
/js
/imageshttps://stackoverflow.com/questions/1891884
复制相似问题