Jur*_*ocs 15 python regex django
您好我有一个网址,我想匹配uuid网址如下所示:
/ mobile/mobile-thing/68f8ffbb-b715-46fb-90f8-b474d9c57134 /
urlpatterns = patterns("mobile.views",
url(r'^$', 'something_cool', name='cool'),
url(r'^mobile-thing/(?P<uuid>[.*/])$', 'mobile_thing', name='mobile-thinger'),
)
Run Code Online (Sandbox Code Playgroud)
但这根本不起作用.我没有调用我的相应视图.我测试了很多变化...... 啊
但是url(r'^mobile-thing/', 'mobile_thing', name='mobile-thinger')工作就像一个魅力,但没有组...
Nic*_*tot 32
该[.*/]表达式只匹配一个字符,它可以是.,*或/.您需要编写代码(这只是众多选项中的一种):
urlpatterns = patterns("mobile.views",
url(r'^$', 'something_cool', name='cool'),
url(r'^mobile-thing/(?P<uuid>[^/]+)/$', 'mobile_thing', name='mobile-thinger'),
)
Run Code Online (Sandbox Code Playgroud)
这里,[^/]代表任何字符,但是/,+在匹配此类字符一次或多次后,右边.你不希望final /在uuidvar中,所以把它放在括号之外.
| 归档时间: |
|
| 查看次数: |
18498 次 |
| 最近记录: |