Question

I am using django-registration app with custom templates, and the django admin. For some reason, the admin template "password_change_form" is being replaced by the custom template from the registration app. I have no idea what I'm doing wrong here. I want the admin to use its own original templates. I'm using Django 1.5. Any help is GREATLY appreciated.

Here is what I have for urlpatterns:

urlpatterns = patterns('',

 url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
 url(r'^admin/', include(admin.site.urls)),

(r'^accounts/', include('registration.backends.default.urls')),
(r'^accounts/profile', views.profile ),

)

And my TEMPLATE_DIRS and INSTALLED_APPS:

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

TEMPLATE_DIRS = (
os.path.join(PROJECT_ROOT, 'templates/'),
os.path.join(PROJECT_ROOT, '../registration/templates/'),
)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'registration',

)

Is there something I am missing??

Was it helpful?

Solution

Ok so finally figured it out. Turns out the django-registration app templates were conflicting with the admin registration templates. To fix this, I changed the folder name where my custom django-registration templates are from "registration" to "myreg" (since the admin registration templates are also under a folder called "registration", which is what I believe was confusing django). Then in the auth_urls.py file of the django-registration app, I changed the template name from "registration/..." to "myreg/..." and added the template name argument to all patterns that don't have it. So auth_urls.py would be like this:

urlpatterns = patterns('',
                   url(r'^login/$',
                       auth_views.login,
                       {'template_name': 'myreg/login.html'},
                       name='auth_login'),
                   url(r'^logout/$',
                       auth_views.logout,
                       {'template_name': 'myreg/logout.html'},
                       name='auth_logout'),
                   url(r'^password/change/$',
                       auth_views.password_change,
                       {'template_name': 'myreg/password_change_form.html'},
                       name='auth_password_change'),
                   url(r'^password/change/done/$',
                       auth_views.password_change_done,
                       {'template_name': 'myreg/password_change_done.html'},
                       name='auth_password_change_done'),
                   url(r'^password/reset/$',
                       auth_views.password_reset,
                       {'template_name': 'myreg/password_reset_form.html'},
                       name='auth_password_reset'),
                   url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
                       auth_views.password_reset_confirm,
                       {'template_name': 'myreg/password_reset_confirm.html'},
                       name='auth_password_reset_confirm'),
                   url(r'^password/reset/complete/$',
                       auth_views.password_reset_complete,
                       {'template_name': 'myreg/password_reset_complete.html'},
                       name='auth_password_reset_complete'),
                   url(r'^password/reset/done/$',
                       auth_views.password_reset_done,
                       {'template_name': 'myreg/password_reset_done.html'},
                       name='auth_password_reset_done'),

)

This should solve the issue and allow Django to use separate templates for admin and django-registration.

OTHER TIPS

A trick how to easily check the order in which template folders are processed.

modify your urls.py to:

from django.views.generic import TemplateView
...

urlpatterns = patterns('',
    ...
    url(r'test/', TemplateView.as_view(template_name="i-dont-exist.html")),
    ...
)

Ensure your settings.DEBUG and TEMPLATE_DEBUG are set to True and load the '/test/' url in your browser. This should return a ErrorPage with a TemplateDoesNotExist Exception. Scroll down to the Template-loader postmortem this shows you the order in which your template folders are checked for files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top