[Django] #33327: Missing template for the LoginView in the contrib.auth.views module

9 views
Skip to first unread message

Django

unread,
Nov 27, 2021, 9:26:13 AM11/27/21
to django-...@googlegroups.com
#33327: Missing template for the LoginView in the contrib.auth.views module
----------------------------------------+------------------------
Reporter: webontos | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+------------------------
Dears,

Django framework raises the following exception while calling the
LoginView (in contrib.auth.views) and using the default template
'registration/login.html':

Exception Type: TemplateDoesNotExist
Exception Value: registration/login.html

I'm using the following URL pattern:

urlpatterns = [
path('accounts/', include('django.contrib.auth.urls')),
]

and then calling the login view via the following URL:
http://127.0.0.1:8000/my_app_name/accounts/login/

After double checking the templates folder in the contrib.auth component,
I can't see any template with the name login.html.

I made a small project to further illustrate the issue:
https://github.com/webontos/missinglogintemplate

In case this is a real bug, I believe the documentation needs to be
updated accordingly:
https://docs.djangoproject.com/en/3.2/topics/auth/default/

I hope I'm not missing anything!

First time to report a potential bug to Django community and I hope this
helps :)


All the best,

--
Ticket URL: <https://code.djangoproject.com/ticket/33327>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 27, 2021, 9:33:19 AM11/27/21
to django-...@googlegroups.com
#33327: Missing template for the LoginView in the contrib.auth.views module
------------------------------+--------------------------------------

Reporter: webontos | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by webontos):

* cc: webontos (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/33327#comment:1>

Django

unread,
Nov 27, 2021, 10:16:19 AM11/27/21
to django-...@googlegroups.com
#33327: Missing template for the LoginView in the contrib.auth.views module
------------------------------------+--------------------------------------
Reporter: Mohammed Iben-ayad | Owner: nobody
Type: Bug | Status: closed
Component: contrib.auth | Version: 3.2
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid


Comment:

It's [https://docs.djangoproject.com/en/3.2/topics/auth/default/#module-
django.contrib.auth.views documented] that ''"Django provides no default
template for the authentication views. You should create your own
templates for the views you want to use. The template context is
documented in each view, see All authentication views."''

--
Ticket URL: <https://code.djangoproject.com/ticket/33327#comment:2>

Django

unread,
Nov 28, 2021, 1:36:48 AM11/28/21
to django-...@googlegroups.com
#33327: Missing template for the LoginView in the contrib.auth.views module
------------------------------------+--------------------------------------
Reporter: Mohammed Iben-ayad | Owner: nobody
Type: Bug | Status: closed
Component: contrib.auth | Version: 3.2
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------

Comment (by Mohammed Iben-ayad):

@Mariusz Felisiak Thanks for your prompt reply! I missed this section
honestly, but I would argue that the documentation is a little bit
confusing - at least from my point of view- since Django provides defaults
templates for the other authentication views such as LogoutView but the
documentation is claiming the opposite ("....Django provides no default
template for the authentication views...") and on the other hand Django
forces you to define a template for the LoginView only by giving a basic
example to start with. Honestly, I'm not arguing, its just I really like
using the framework and trying to understand the bottom line and adhere to
the general consensus. Great thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/33327#comment:3>

Django

unread,
Aug 12, 2022, 7:03:07 AM8/12/22
to django-...@googlegroups.com
#33327: Missing template for the LoginView in the contrib.auth.views module
------------------------------------+--------------------------------------
Reporter: Mohammed Iben-ayad | Owner: nobody
Type: Bug | Status: closed
Component: contrib.auth | Version: 3.2
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------

Comment (by slowkow):

There is a sample template on this page:

https://docs.djangoproject.com/en/4.1/topics/auth/default/#built-in-auth-
forms

Could I please ask if you would go ahead and copy this sample directly
into the "polls app" tutorial? This would help newcomers to understand how
to make the login page.

I copied the sample below:

"Here is the a sample registration/login.html template you can use as a
starting point. It assumes you have a base.html template that defines a
content block:"

{{{
{% extends "base.html" %}

{% block content %}

{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}

{% if next %}
{% if user.is_authenticated %}
<p>Your account doesn't have access to this page. To proceed,
please login with an account that has access.</p>
{% else %}
<p>Please login to see this page.</p>
{% endif %}
{% endif %}

<form method="post" action="{% url 'login' %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>

<input type="submit" value="login">
<input type="hidden" name="next" value="{{ next }}">
</form>

{# Assumes you set up the password_reset view in your URLconf #}
<p><a href="{% url 'password_reset' %}">Lost password?</a></p>

{% endblock %}
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33327#comment:4>

Reply all
Reply to author
Forward
0 new messages