Ad

How To Use Base_template Variable In Django Login.html

- 1 answer

I have a very simple Django 3.1 project that uses the basic login-authentication found in the Mozilla tutorial (https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Authentication).

It works great, but I'd like to change the extends base_generic line to a variable.

For example, logged_out.html, currently looks like this:

{% extends "base_generic.html" %}

{% block content %}
  <p>Logged out!</p>
  <a href="{% url 'login'%}">Click here to login again.</a>
{% endblock %}

I'd like it to look like this:

{% extends base_template %}  <-- Here's the change I'd like to make

{% block content %}
  <p>Logged out!</p>
  <a href="{% url 'login'%}">Click here to login again.</a>
{% endblock %}

I've been able to do this successfully for all the templates that I create, but I can't figure out how to do this for the "built-in" login-authentication pages, such as login.html, logged_out.html, password_reset_form.html, etc

Thank you!

Ad

Answer

you can define your own template and change urls.py. Example changing a template for auth_views.LogoutView:

urlpatterns = [

path('logout/',
   auth_views.LogoutView.as_view(template_name='customers/logout.html'), 
   name='logout'),
]
Ad
source: stackoverflow.com
Ad