My Url's supplied by django registration redux don't work when the following url is used:
url(r'^(?P<username>\w+)/(?P<slug>[-\w]+)/$', views.project_page, name='user_project'),
but then they do work if I add another level to that url like this:
url(r'^projects/(?P<username>\w+)/(?P<slug>[-\w]+)/$', views.project_page, name='user_project'),
I don't want to add that extra project/ url level in there if possible. Why would it be effecting the django registration redux url's and how can I fix it? Any help would be much appreciated :-)
project urls
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf import settings
from registration.backends.simple.views import RegistrationView
class MyRegistrationView(RegistrationView): #redirects to home page after registration
def get_success_url(self,request, user):
return '/register_profile'
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'', include('howdidu.urls')),
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'), #redirects to home page after registration
(r'^accounts/', include('registration.backends.simple.urls')),
)
# media
if settings.DEBUG:
urlpatterns += patterns(
'django.views.static',
(r'^media/(?P<path>.*)',
'serve',
{'document_root': settings.MEDIA_ROOT}), )
app urls
from django.conf.urls import patterns, url
from howdidu import views
from django.contrib.auth.decorators import login_required
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^register_profile/$', views.register_profile, name='register_profile'),
url(r'^update_profile/$', views.update_profile, name='update_profile'),
url(r'^create_project/$', login_required(views.CreateProject.as_view()), name='create_project'),
url(r'^(?P<username>\w+)/$', views.profile_page, name='user_profile'),
url(r'^(?P<username>\w+)/(?P<slug>[-\w]+)/$', views.project_page, name='user_project'),
)
The problem is your url ordering, take a look at this:
url(r'^admin/', include(admin.site.urls)),
url(r'', include('howdidu.urls')),
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'), #redirects to home page after registration
url(r'^accounts/', include('registration.backends.simple.urls')),
Especially this:
url(r'', include('howdidu.urls')),
this url matches everything, so basically Django will go from the top to the bottom and if it doesn't find any match before url(r'', include('howdidu.urls'))
, it will match anything to it. This means that you will never match
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'), #redirects to home page after registration
url(r'^accounts/', include('registration.backends.simple.urls')),
One way to fix it is to place url(r'', include('howdidu.urls'))
at the very bottom of the urls:
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'), #redirects to home page after registration
url(r'^accounts/', include('registration.backends.simple.urls')),
url(r'^', include('howdidu.urls')),
and another way is to set another url level for url(r'^', include('howdidu.urls'))
:
url(r'^admin/', include(admin.site.urls)),
url(r'^howdidu/', include('howdidu.urls')),
url(r'^accounts/register/$', MyRegistrationView.as_view(), name='registration_register'), #redirects to home page after registration
url(r'^accounts/', include('registration.backends.simple.urls')),