Geoff
Geoff

Reputation: 2491

Django URL not resolving

I think this is a case of staring at the code for too long, but I can't get this URL to resolve. I'm using Django 1.5.5.

Here's the main urls.py:

from django.conf.urls import patterns, include, url
from django.views.generic import RedirectView

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^$', RedirectView.as_view(url='/swap/')),
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    url(r'^swap/$', include('apps.swap.urls')),
    url(r'^admin/swap/', include('apps.swap.admin_urls')),
    url(r'^admin/', include(admin.site.urls)),
)

Here's my app's url.py:

from django.conf.urls import patterns, url
from apps.swap.views import About

urlpatterns = patterns('apps.swap.views',
        url(r'^$', 'index'),
        url(r'^about/$', About.as_view()),
)

All URLs resolve (including /swap/) except for /swap/about/. It just refuses to resolve. This is what I see:

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

1. ^__debug__/sql_select/$ [name='sql_select']
2. ^__debug__/sql_explain/$ [name='sql_explain']
3. ^__debug__/sql_profile/$ [name='sql_profile']
4. ^__debug__/template_source/$ [name='template_source']
5. ^$
6. ^admin/doc/
7. ^swap/$
8. ^admin/swap/
9. ^admin/

The current URL, swap/about/, didn't match any of these.

What am I missing here? I know it's got to be something simple, but after a 16 hour coding bender last night, I think I've gone blind.

Upvotes: 0

Views: 692

Answers (1)

Maciej Gol
Maciej Gol

Reputation: 15854

url(r'^swap/$', include('apps.swap.urls'))

The $ at the end is the bad boy here. It matches the end of the string, thus obviously rejecting swap/about.

Upvotes: 4

Related Questions