سؤال

I am trying to connect my urls together after installing the django-registration app

My main project is called Club , here is club/club/urls.py:

from django.conf.urls import patterns, include, url
from blog import views
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

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

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
    url(r'^addauthor$', views.addauthorView),
    url(r'^thanks/$', views.thanksView),
    url(r'^displayauthors/$', views.displayauthors),
    # registration links below
    url(r'^reg/', include('club.registration.urls')),

)   

And here is my club/registration/urls.py:

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

urlpatterns = patterns('',
url(r'^accounts/', include('registration.backends.default.urls')),
)

Am I connecting these two correctly? Or is there another way to do it?

When trying to visit http://127.0.0.1:8000/reg/accounts/login/ in browser I get an error message:

ImportError at /reg/accounts/login/
No module named registration.urls
هل كانت مفيدة؟

المحلول

Is there a reason you have a "registrations" app (i.e. club/registrations/url)? Not trying to be a jerk; honestly wondering. There are reasons to do so, but if you're not making any big changes, it'd probably just be easy to link straight from the root url conf.

If you want to just use the django-registration app wholesale, your root url conf (club/club/urls.py) could say:

url(r'^reg/', include('registration.backends.default.urls')),. Note that you could change r'^reg/' to whatever you wanted the url to be. To link to it, you would then go to http://127.0.0.1:8000/reg/login

If you do have a reason for having a 'registrations' app (which means you have a separate 'club/registrations/' directory), that's fine too. You just don't need the 'club' in your include link for the root url conf (club/club/urls.py):

url(r'^reg/', include('registration.urls')),

Then your original link should work: http://127.0.0.1:8000/reg/accounts/login/

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top