Django-urls.py REGEX [英] Django - urls.py REGEX

查看:66
本文介绍了Django-urls.py REGEX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在为Django项目编写url的正则表达式部分时遇到了麻烦。

I am having some trouble writing the regex portion of the url for a Django project.

我希望能够与捕获配置文件ID一起路由

I want to be able to route along with capturing a profile ID

URL示例:www.somesite.com/profile/12345678901

URL Example: www.somesite.com/profile/12345678901

这就是我到目前为止

url(r'^profile/$', views.dashboard, name='widget')

在配置文件/之后应该使用什么正确的REGEX?
如何捕获配置文件/之后的数字部分?

Whats the correct REGEX that should go after the profile/? How would I capture the numeric part after the profile/? once I am in the view?

谢谢

推荐答案

url(r'^profile/(?P<id>[\d]+)/$', profile_view, name="profile"),

并在视图中

def profile_view(request, id):
    #some logic here...

这篇关于Django-urls.py REGEX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆