Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

376
Vistas
How to raise django validation error on login form (which is on a bootstrap modal on index.html)?
#below is login view
def login_view(request):
        print(request.user.is_authenticated())
        next = request.GET.get('next')
        title = "Login"
        form = UserLoginForm(request.POST or None)
        if form.is_valid():    
            username = form.cleaned_data.get("username")
            password = form.cleaned_data.get('password')
            user = authenticate(username=username, password=password)
            login(request, user)        
            if next:
                return redirect(next)
            return redirect("/userdashboard")
        return render(request, "index.html", {"form":form, "title": title})

how can i return error message on login form (which is in bootstrap modal)

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can use a Http404 condition to render error message on login. Import Http404 the class is django.http.Http404 if you raise any error in that case Django will return the error message or page that you set to be displayed ex: 404.html. You code may look like this:

def login_view(request):
    print(request.user.is_authenticated())
    next = request.GET.get('next')
    title = "Login"
    form = UserLoginForm(request.POST or None)
    try:
        if form.is_valid():    
            username = form.cleaned_data.get("username")
            password = form.cleaned_data.get('password')
            user = authenticate(username=username, password=password)
            login(request, user)        
            if next:
                return redirect(next)
            return redirect("/userdashboard")
    except:
        raise Http404 (" This user does not exist.")
    return render(request, "index.html", {"form":form, "title": title})
about 4 years ago · Santiago Trujillo Denunciar

0

inside the bootstrap modal use form errors in loop.

{% if form.errors %}
    {% for field in form %}
        {% for error in field.errors %}
            <div class="alert alert-danger">
                <strong>{{ error|escape }}</strong>
            </div>
        {% endfor %}
    {% endfor %}
    {% for error in form.non_field_errors %}
        <div class="alert alert-danger">
            <strong>{{ error|escape }}</strong>
        </div>
    {% endfor %}
{% endif %}
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda