'^ site_media /(?P< path>。*)$'的含义 [英] Meaning of '^site_media/(?P<path>.*)$'
本文介绍了'^ site_media /(?P< path>。*)$'的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
# urls.py
site_media = os.path.join(os.path.dirname(__file__), 'site_media'
)
urlpatterns = patterns('',
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': site_media}),
)
我有问题要了解所用表达式的含义在上面的陈述中。
I have problems to understand the meaning of the expression used in above statement.
'^site_media/(?P<path>.*)$'
这是什么意思?
谢谢
// ==========根据评论更新==============
// ========== Updated based on comments ==============
参考:名称组。
在Python正则表达式中,命名的regular-expression
组的语法为(?P< name> pattern)
,其中名称是组的名称,
In Python regular expressions, the syntax for named regular-expression
groups is (?P<name>pattern)
, where name is the name of the group and
pattern is some pattern to match.
比较:
方法1 >
(r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/$', 'news.views.month_archive'),
要求 / articles / 2005/03 /
将调用函数
news.views.month_archive(request,year ='2005',month = '03')
,
方法2 >
(r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'),
请求 / articles / 2005/03 /
将调用函数
news.views.month_archive(request, '2005','03')
。
推荐答案
urls在文档
这篇关于'^ site_media /(?P< path>。*)$'的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文