django的资源文件

  刚看了怎么在django的工程中加入资源文件夹,即放一些静态内容,像html页面,css文件什么的,其实放在外面也可以,但是总感觉有些怪,还好step by step讲到了这一课,其实也没什么难的,它给的例子是在urls.py中加了一行,以解析URL,然后在settings.py中加上了一个相当于常量定义的命令,把一个目录定义成常量,然后在网站根目录下建立了这个目录,于是,就可以了。urls.py中更改的和以前有些不太相同,使用了django.views.static.serve,而此参数需要一个参数,文档根目录,所以需要在后面加上{‘document_root’: settings.STATIC_PATH}),那个settings.需要在开头加上import django.conf import settings以导入模块。其它在网页中就可以使用/site_media来访问./media目录了,那个site_media是在urls.py中定义的,那个patten也有些不同,后面加上了一些东西,r’^site_media/(?P<path>.*)$’,还没太弄懂,过过再说。

This entry was posted in Happy coding. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>