[Python] why do i get Forbidden (403) CSRF verification failed. Request aborted. when I'm...

Discussão em 'Python' iniciado por Stack, Junho 15, 2025.

  1. Stack

    Stack Membro Participativo

    from django.shortcuts import render
    from django.contrib.auth import authenticate, login
    from django.contrib.auth.forms import UserCreationForm

    def register(response):
    if response.method == 'POST':
    form = UserCreationForm(response.POST)
    if form.is_valid():
    form.save()
    else:
    form = UserCreationForm()

    return render(response, 'register/register.html', {'form':form})



    html

    {% extends 'libraryfinish/base.html' %}

    {% block title %}
    Create an account
    {% endblock %}

    {% block content %}
    <form method="POST", class="form-group">
    {% csrf_token %}
    {{form}}
    <button type="submit", class="btn btn-success">Register</button>
    </form>
    {% endblock %}


    I found that I should pass the RequestContext in my render_to_response for the context processors to actually be run, but I'm not using render to response

    from django.views.decorators.csrf import csrf_protect

    @csrf_protect doesn't work

    Continue reading...

Compartilhe esta Página