urls.py


urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^comments/', include('django.contrib.comments.urls')),
url(r'^static/(?P<path>.*)$',                      'django.views.static.serve',       {'document_root': settings.STATIC_ROOT },name='static'),
url(r'^media/(?P<path>.*)$',                     'django.views.static.serve',      {'document_root': settings.MEDIA_ROOT },name='media'),
url(r'^js/(?P<path>[\w\.\-]+\.js)$',              'django.views.static.serve',     {'document_root':os.path.join(os.path.dirname(__file__),"./templates/js")},name='js'),
url(r'css/(?P<path>[\w\.\-]+\.css)$',           'django.views.static.serve',    {'document_root':os.path.join(os.path.dirname(__file__),"./templates/css")},name='css'),
url(r'images/(?P<path>[\w\.\-]+\.*)$',           'django.views.static.serve',  {'document_root':os.path.join(os.path.dirname(__file__),"./templates/images")},name='images'),
 
)
 
遇到符合第一区块匹配的地址,通通作为静态文件处理,使用第二区块的方法,然后在第三区块中寻找静态路径。
 
 
这里,第一块红色,是 命名组,给后面的匹配起了个别名。
 
绿色的部分,是正则匹配
.*       是指任意字符匹配任意次,即无限制
[ \w \. \- ] 是指 [ ] 内符合哪个都行。其中, \w是普通字符; \. 是 .  ;\ - 是 -
[ ]+          是指把 [ ] 里的东西,进行 >=1 次匹配
 
(?P<path>[\w\.\-]+\.css)  是指按【】内匹配一次或多次,以 .css结尾 的。此匹配的别名是path。对应的处理函数是   'django.views.static.serve' ,对应的路径参数是{ document_root : }
 

相关内容

    暂无相关文章

评论关闭