URL matching problem

52 views
Skip to first unread message

Ma Yuping

unread,
Mar 23, 2015, 10:19:27 PM3/23/15
to django-d...@googlegroups.com
django V1.6.8

Let URL be:

url(r'^blog/(?P<user_id>\d+)/$', views.index, name='index'),

url(r'^blog/(?P<user_id>\d+)/article/(?P<article_id>\d+)/view/$', views.article, name='article'),


Input following urls to the the browser:

blog/1/

blog/1/1/

blog/1/article/1/

blog/1/1/1/1/article/1/1/1/1/

blog/bb/1/1/1/

...

They all go to the same view: 'index'


Curtis Maloney

unread,
Mar 23, 2015, 10:45:33 PM3/23/15
to django-d...@googlegroups.com
Firstly, this is really a question for django-users ... this mailing list is for discussion of the development _of_ Django, not _with_ Django.

On 24 March 2015 at 13:16, Ma Yuping <mayup...@gmail.com> wrote:
django V1.6.8

Let URL be:

url(r'^blog/(?P<user_id>\d+)/$', views.index, name='index'),

url(r'^blog/(?P<user_id>\d+)/article/(?P<article_id>\d+)/view/$', views.article, name='article'),


Are you certain these are the exact patterns you have, and the only patterns starting with blog/ ?

Either you've not restarted your app server after making changes, or you have another url pattern that's catching all of these.

--
Curtis

Ma Yuping

unread,
Mar 24, 2015, 7:12:41 AM3/24/15
to django-d...@googlegroups.com
It solved.
It should be exact: I should put '^' before the APP's URL. 

url(r'^(?P<user_id>\d+)/$', views.index, name='index'),

url(r'^(?P<user_id>\d+)/article/(?P<article_id>\d+)/$', views.article, name='article'),

Thanks




在 2015年3月24日星期二 UTC+8上午10:45:33,Curtis Maloney写道:

Ma Yuping

unread,
Mar 24, 2015, 7:12:41 AM3/24/15
to django-d...@googlegroups.com
Actually:
In my project url, I have:

urlpatterns = patterns('',

url(r'^blog/', include('blog.urls', namespace="blog")), 

)

In the App, I have:

urlpatterns = patterns('',

#url(r'/$', views.index, name='index'),

url(r'(?P<user_id>\d+)/$', views.index, name='index'),

url(r'(?P<user_id>\d+)/article/(?P<article_id>\d+)/$', views.article, name='article'),

url(r'(?P<user_id>\d+)/resume/$', views.resume, name='resume'),

url(r'write/$', views.write.as_view(), name='write'),

)



在 2015年3月24日星期二 UTC+8上午10:45:33,Curtis Maloney写道:
Firstly, this is really a question for django-users ... this mailing list is for discussion of the development _of_ Django, not _with_ Django.
Reply all
Reply to author
Forward
0 new messages