Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Included URLconf "does not appear to have any patterns in it"

I'm on Django 1.7.

The two urls.py files are configured correctly. I have a project urls (with the appropriate include) and an app urls with the proper set up. The urls work perfectly.

Unless, on my RedirectView, I put this: url = reverse('x')

If I try to use reverse I get this error The included urlconf '<project>.urls' does not appear to have any patterns in it.

Removing the offending line and refreshing doesn't fix the problem. I have to restart the django server which will fix it.

reverse('x') does work and I use it in other CBVs.

Project urls.py:

from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'app_repo.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),

url(r'^admin/', include(admin.site.urls)),
url(r'^users/', include('django_users.urls')),
)

App urls.py:

from django.conf.urls import patterns, include, url
import django_users.views

urlpatterns = patterns('',
  # Users
  url(r'^register/$', django_users.views.RegisterUser.as_view(),
      name='register-user'),
  url(r'^login/$', django_users.views.LoginUser.as_view(),
      name='login-user'),
  url(r'^logout/$', django_users.views.LogoutUser.as_view(),
      name='logout-user'),
  url(r'^password/$', django_users.views.PasswordChangeUser.as_view(),
      name='password-change-user'),
)
like image 358
Colton Allen Avatar asked Oct 24 '25 03:10

Colton Allen


1 Answers

A class-level attribute in a View class will be assigned at import time. URL-resolving is not yet set up at import time, however, so it may not yet work.

The error message is due to Django stumbling over its own feet when trying to use it anyway.

Solution: You will have to put the assignment into a getter method to postpone the lookup or use reverse_lazy.

See https://stackoverflow.com/a/7249228/2810305

like image 177
Lutz Prechelt Avatar answered Oct 25 '25 17:10

Lutz Prechelt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!