我的Django模板使用了很多相关的东西:图片、样式表等等。这些文件应该放在哪里,或者在模板本身中如何引用它们?目前我正在使用开发服务器。我知道这是一个非常常见的问题,但我真的搞不清楚。
(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('\\', '/')
我们把静态文件放在 /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
/images