2

I wrote specific templates to deal with password reset and change,
the file tree structures as:

In [3]: !tree /Users/me/desktop/Django/forum/user/templates
/Users/me/desktop/Django/forum/user/templates
├── registration
│   ├── logged_out.html
│   ├── login.html
│   ├── password_change_done.html
│   ├── password_reset_complete.html
│   ├── password_reset_confirm.html
│   ├── password_reset_done.html
│   └── password_reset_form.html
└── user
    ├── activate.html
    ├── failure.html
    ├── register.html
    ├── success.html
    └── validate.html

The project urls is configured as:

# Project url
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r"^$", views.index, name="index"),
    url(r'^article/', include('article.urls',namespace='article')),
    url(r'^user/', include('user.urls',namespace='user')),
    url(r'^user/', include('django.contrib.auth.urls')),
]

Unfortunately, when I try to issue request as http://127.0.0.1:8001/user/password_reset/,
the browser redirect to its default admin site

enter image description here I am working on Django 1.11

How reference 'django.contrib.auth.urls' to my own templates?

1
  • 1
    have you written your own views for password reset, change urls?. Anyway, you have 2 urls for r'^user/'. The 2nd one will just override the first one and I believe that is why you see admin page. Remove the 2nd one and you should see your custom view Jun 5, 2018 at 5:54

4 Answers 4

3

If you just want to override admin templates, you can just add admin directory and templates in your template dir.

It's well explained in django official docs (https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates)

If you want to override view either, you have to make your own app and match it to urls.

2
  • ty but I did not want to override admin site, I intent to employ its views and urls to my own app.
    – Wizard
    Jun 5, 2018 at 6:32
  • Then you can make your own apps - then it means you don't have to override auth, you just make your own view and urls.
    – seuling
    Jun 5, 2018 at 8:00
0

You can also pass template_name as variable...:

in urls.py:

from django.contrib.auth import views as auth_views
urlpatterns = [
    url(r'^user/login-custom-template/$', auth_views.login, {'template_name': 'path-to-custom-template.html'}, name='login-custom'),
]
0
0

To ref to your template, in case it doesn't work just use template name:

urlpatterns = [
    path(
        'change-password/',
        auth_views.PasswordChangeView.as_view(template_name='change-password.html'),
    ),
]

OR:

Even skip django.contrib.auth.urls if you want to use another directory template not in registration, in this case I point to template /basic_app/

from django.contrib.auth import views as auth_views

AND

re_path(r'^login/$',auth_views.LoginView.as_view(template_name='basic_app/login.html'),name='login')
0

Analyzing the same problem while doing this tutorial:

I discovered that You can skip 'admin' route described earlier and just move Your users app above other apps in settings:

INSTALLED_APPS = [
    'users',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # External apps
    'taggit',
    # My apps
    'projekty',
    'blog',
]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.