在哪里放置Django模板的依赖文件? [英] Where to put a Django template's dependent files?

查看:97
本文介绍了在哪里放置Django模板的依赖文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My Django templates use a lot of related stuff: images, style sheets, etc.

我应该把这些文件放在哪里,或者我应该怎么参考模板本身?

Where should I put these file, or how should I refer to them in the template itself?

现在我正在使用开发服务器。

For now I'm using the development server.

我知道这是一个很常见的事情,但我不能真正弄清楚。

I know it's a really common thing, but I can't really figure it out.

推荐答案

我把它们放在一个名为静态,它位于Web项目的顶级文件夹中。

I put them inside a folder named static, which is in the web project's top level folder.

示例:


/ static / img /

/ static / js /

/ static / css /

/ templates /

urls.py

settings.py


/static/img/
/static/js/
/static/css/
/templates/
urls.py
settings.py

然后,我的 urls.py 文件中有以下规则:

I then have the following rule in my urls.py file:

(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('\\', '/')

这篇关于在哪里放置Django模板的依赖文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆