在哪里放置Django模板的相关文件?

时间:2009-12-12 01:23:58

标签: python django django-templates

我的Django模板使用了很多相关的东西:图像,样式表等。

我应该把这些文件放在哪里,或者我应该如何在模板中引用它们?

目前我正在使用开发服务器。

我知道这是非常普遍的事情,但我无法弄明白。

3 个答案:

答案 0 :(得分:5)

我将它们放在名为static的文件夹中,该文件夹位于Web项目的顶级文件夹中。

示例:

  

/静态/ IMG /
  /静态/ JS /
  /静态/ 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('\\', '/')

答案 1 :(得分:2)

答案 2 :(得分:0)

我们把我们放在/ 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
相关问题