New to Django cannot figure URLpatterns

185 views
Skip to first unread message

Mark Strickland

unread,
Oct 14, 2013, 6:58:38 PM10/14/13
to django...@googlegroups.com
I am new to using Django and I can get one urls to work, but I cannot get another.  I am running Django 1.5

This url works.

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

But if I try to follow this one.

 url(r'^(?P<pluginTitle>\D+)/$', views.detail, name='detail'),

I get the following error.when I try http://127.0.0.1:8000/plugin/title where title is a unique key in the database.

Page not found (404)

Request Method:GET
Request URL:http://127.0.0.1:8000/plugin/cbs/

Using the URLconf defined in urlconf, Django tried these URL patterns, in this order:

    1. ^__debug__/m/(.*)$
    2. ^__debug__/sql_select/$ [name='sql_select']
    3. ^__debug__/sql_explain/$ [name='sql_explain']
    4. ^__debug__/sql_profile/$ [name='sql_profile']
    5. ^__debug__/template_source/$ [name='template_source']
    6. ^admin/doc/
    7. ^admin/
    8. ^plugin/ ^(?P<pluginTitle>\d+)/$ [name='detail']
    9. ^plugin/ ^$ [name='index']
The current URL, plugin/cbs/, didn't match any of these. 

Any and all help or guidance would be greatly appreciated. 

Tom Lockhart

unread,
Oct 14, 2013, 7:08:18 PM10/14/13
to django...@googlegroups.com
On 2013-10-14, at 3:58 PM, Mark Strickland <sms...@roadrunner.com> wrote:

I am new to using Django and I can get one urls to work, but I cannot get another.  I am running Django 1.5

This url works.

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

But if I try to follow this one.

 url(r'^(?P<pluginTitle>\D+)/$', views.detail, name='detail'),

Look at item 8 in the debug message below. I think you want something like

url(r'^/plugin/(?P<pluginTitle>\D+)/$', views.detail, name='detail'),

for the URL you want to match.

hth

                 - Tom



I get the following error.when I try http://127.0.0.1:8000/plugin/title where title is a unique key in the database.

Page not found (404)

Request Method:GET
Request URL:http://127.0.0.1:8000/plugin/cbs/

Using the URLconf defined in urlconf, Django tried these URL patterns, in this order:

    1. ^__debug__/m/(.*)$
    2. ^__debug__/sql_select/$ [name='sql_select']
    3. ^__debug__/sql_explain/$ [name='sql_explain']
    4. ^__debug__/sql_profile/$ [name='sql_profile']
    5. ^__debug__/template_source/$ [name='template_source']
    6. ^admin/doc/
    7. ^admin/
    8. ^plugin/ ^(?P<pluginTitle>\d+)/$ [name='detail']
    9. ^plugin/ ^$ [name='index']
The current URL, plugin/cbs/, didn't match any of these. 

Any and all help or guidance would be greatly appreciated. 

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3d625e8e-ff23-4411-a0e2-503b8496c286%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Tom Evans

unread,
Oct 15, 2013, 4:38:00 AM10/15/13
to django...@googlegroups.com
On Mon, Oct 14, 2013 at 11:58 PM, Mark Strickland
<sms...@roadrunner.com> wrote:
>
> I am new to using Django and I can get one urls to work, but I cannot get another. I am running Django 1.5
>
> This url works.
>
> url(r'^$', views.index, name='index'),
>
>
> But if I try to follow this one.
>
> url(r'^(?P<pluginTitle>\D+)/$', views.detail, name='detail'),
>
>
> I get the following error.when I try http://127.0.0.1:8000/plugin/title where title is a unique key in the database.
>
> Page not found (404)

Your regular expression is bogus. Presumably (given the error messages
I've chopped) that URL is in a urlconf that has a prefix of
"/plugin/", so ignore what Tom Lockhart said about that.

Your regexp is:

r'^(?P<pluginTitle>\D+)/$'

This says "From the beginning of the string, capture a grouping of 1
or more characters from the class '\D' as the parameter 'pluginTitle',
followed by a '/' character, followed by the end of the string.

The main problem is that there is no such character class '\D'. There
is '\d', it means the digits 0-9, but you are trying to match the word
'title'. Work out what are valid characters for your title and write
the regular expression accordingly.

Cheers

Tom

Bill Freeman

unread,
Oct 15, 2013, 9:30:25 AM10/15/13
to django-users
Actually, there is a character class \D; it matches any NON-digit.  As such this should match title, as long as it contains non digits.

But looking at this line from the error message:

  8. ^plugin/ ^(?P<pluginTitle>\d+)/$ [name='detail']

It appears that you are actually using the little \d, contrary to the url pattern that you quoted.  That would only match titles that were composed entirely of digits.

Be sure which one is there.

You may actually want \w, or even [^/].

Bill


--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages