On 9/9/13 3:30 PM, Chris Kavanagh wrote:
I haven't used this group in a long time, so I hope I do everything
correctly. If I don't, I apologize in advance.
I thought I understand the way django uses URL's in the urlconf to
match URL's, but I was wrong. Here's my question:
Here's my urlconf. . .
url(r'^all/$', 'article.views.articles'),
url(r'^get/(?P<article_id>\d+)/$', 'article.views.article'),
url(r'^language/(?P<language>[a-z\-]+)/$', 'article.views.language'),
url(r'^create/$', 'article.views.create'),)
and here's the other one in the site directory.
urlpatterns = patterns('',
(r'^articles/', include('article.urls')),
url(r'^accounts/login/$', 'mysite.views.login'),
url(r'^accounts/auth/$', 'mysite.views.auth_view'),
url(r'^accounts/logout/$', 'mysite.views.logout'),
url(r'^accounts/loggedin/$', 'mysite.views.loggedin'),
url(r'^accounts/invalid/$', 'mysite.views.invalid_login'),
url(r'^accounts/register/$', 'mysite.views.register_user'),
url(r'^accounts/register_success/$',
'mysite.views.register_success'),)
Here's the question: If I have the URL
"http://127.0.0.1:8000/articles/create/" it works fine and takes me to
the correct page. But why does it work when I have the "/article" in
the url. According to the urlconf last entry r'^create/$', it should
only match a url with "/create" NOT a url with "/article/create". The
caret means "starts with" and the $ means "end with", so to get to the
"create" page it should be a url with just "/create/" in it, right?
I'm a bit confused by your question. All of your "urlconf" paths will
need to have "/articles" in the path to be found. Although regex does
use "^" and "$" to denote beginning and end, you have split your pattern
matching into two stages so they are just matching the pattern available
in each stage.
Was your mention of "/article" above a typo and you meant "/articles"?
You might want to follow up with a description of what behavior you need
to help folks give you a solution.
hth
- Tom
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.