Skip to content


开发Django时引用CSS和JS

开始照着Django的教程做的应用,没有用到css和js,没有讲到这个问题。所以在实际用到css和js时,才发现这个问题,我发现最方便的方法是在应用的urls.py的映射当中,增加这两行:

(r’^css/(?P<path>.*)$’, ‘django.views.static.serve’,{‘document_root’: ‘F:/rocksun/rstools/template/css’}),
(r’^images/(?P<path>.*)$’, ‘django.views.static.serve’,{‘document_root’: ‘F:/rocksun/rstools/template/images’}),

这样设置之后,模板中对于/css的请求就会进入我设置的F:/rocksun/rstools/template/css目录下,同理images,不需要设置media目录了。

Related posts:

  1. 完成三个在线转化功能
  2. 简繁体转化工具
  3. 在我的Blog网站上运行Django
  4. Django 1.0之后的文件上传
  5. Linux下的Subversion,难啊

Posted in program. Tagged with , , , , .

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.