Opened 2 years ago

Closed 2 years ago

Last modified 21 months ago

#33327 closed Bug (invalid)

Missing template for the LoginView in the contrib.auth.views module

Reported by: Mohammed Iben-ayad Owned by: nobody
Component: contrib.auth Version: 3.2
Severity: Normal Keywords:
Cc: Mohammed Iben-ayad Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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,

Change History (4)

comment:1 by Mohammed Iben-ayad, 2 years ago

Cc: Mohammed Iben-ayad added

comment:2 by Mariusz Felisiak, 2 years ago

Resolution: invalid
Status: newclosed

It's 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."

comment:3 by Mohammed Iben-ayad, 2 years ago

@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!

comment:4 by Kamil Slowikowski, 21 months ago

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 %}
Note: See TracTickets for help on using tickets.
Back to Top