0

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
ApathyBear
  • 9,057
  • 14
  • 56
  • 90

1 Answers1

2

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/

Alex
  • 8,321
  • 1
  • 34
  • 30
  • _Is there a reason you have a "registrations" app (i.e. club/registrations/url)?_ Well, I figured I would eventually have a views for my Registration, and keeping all the registration parts in one folder just seemed like a good idea. Is this not a good approach to writing reusable code? – ApathyBear Mar 27 '14 at 23:49
  • Taken from django-registration: _Two views are provided: registration.backends.default.views.RegistrationView and registration.backends.default.views.ActivationView. These views subclass django-registration’s base RegistrationView and ActivationView, respectively, and implement the two-step registration/activation process._ It just seems like the folder was necessary, but I suppose the urls itself doesn't have to be. In fact I wish I could just have all my pip installed apps have a folder, it makes it more clear. *shrug* – ApathyBear Mar 27 '14 at 23:53
  • You don't need the folder in your project. It will search your project and then the django-registration package. Basically, you're borrowing an app set up by django-registration.It really depends on the package and your needs. As you've shown, django-registration has some views. It also has a default URL conf, which you've linked to (`registration.backends.default.urls`). This means you're piggybacking on those urls and the views they call. It looks like, at the very least, django-registration still requires you to make your own templates. See quickstart instructions-"Required Templates" – Alex Mar 28 '14 at 00:04