Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
Is there a way to show login error in Django?

I have a custom login page for my web. Upon keying the right account details, I can log in to my web. But if I key in wrong account details, it just refreshes the pages with the username and password 's textbox empty. Is there some way to show something like 'Username or Password is wrong' as a error or message?

Within the login.html I have the following

{% if messages %}
{%for message in messages%}
<div class ="alert alert-success" role="alert">
{{message}}
</div>
{%endfor%}
{%endif%}

{% for field in form %}        
{% if field.errors %}        
{% for error in field.errors %}
<div class="alert alert-danger" role="alert">
 <div class="d-flex flex-row">
  <div class="align-middle pr-2">
   <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
                                                class="bi bi-x-circle-fill" viewBox="0 0 16 16">
                                                <path
                                                    d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM5.354 4.646a.5.5 0 1 0-.708.708L7.293 8l-2.647 2.646a.5.5 0 0 0 .708.708L8 8.707l2.646 2.647a.5.5 0 0 0 .708-.708L8.707 8l2.647-2.646a.5.5 0 0 0-.708-.708L8 7.293 5.354 4.646z" />
    </svg>
   </div>
  <div class="align-middle"><b>{{field.label}}</b> - {{error}}</div>
 </div>
</div>
{% endfor %}
{% endif %}
{% endfor %}

The following does not seem to do anything if the username or password is incorrect.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

try to add this in your template

{% if form.errors %}
    <p>username or password is wrong</p>
{% endif %}
about 4 years ago · Juan Pablo Isaza Report

0

In any web application, we need to display notification messages to the end user after processing a form or some other types of his requests. To make this messaging system simple, Django provided full support to cookie and session based messaging for both anonymous and authenticated users.

This messages framework is capable of storing messages in one request and retrieving those messages in the subsequent request. Every message has a tag based on its priority(info,warning and error).

For more information click here.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!