Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6794899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:16:39+00:00 2026-05-26T18:16:39+00:00

Beginner at Django here, I’ve been trying to fix this for a long time

  • 0

Beginner at Django here, I’ve been trying to fix this for a long time now.
I do have ‘django.middleware.csrf.CsrfViewMiddleware’ in my middleware classes and I do have the token in my post form.

Heres my code, what am I doing wrong?

from django.contrib.auth.forms import UserCreationForm
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from chartsey.authentication.forms import RegistrationForm
from django.template import RequestContext
from django.core.context_processors import csrf

def register(request):

    if request.method == 'POST':
        c = RequestContext(request.POST, {})
        form = RegistrationForm(c)
        if form.is_valid():
            new_user = form.save()
            return HttpResponseRedirect("/")
    else:
        form = RegistrationForm()

    return render_to_response("register.html",  {'form': form,  }, )

Here’s my Template:

{% block content %}

    <h1>Register</h1>
    <form action="" method="POST"> {% csrf_token %}
        {{ form.as_p }}
    <input type="submit" value="Submit">
    </form>

{% endblock %}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:16:40+00:00Added an answer on May 26, 2026 at 6:16 pm

    Update: This answer is from 2011. CSRF is easy today.

    These days you should be using the render shortcut function return render(request, 'template.html') which uses RequestContext automatically so the advice below is outdated by 8 years.

    1. Use render https://docs.djangoproject.com/en/2.2/topics/http/shortcuts/
    2. Add CSRF middleware https://docs.djangoproject.com/en/2.2/ref/csrf/
    3. Use the {% csrf_token %} template tag
    4. Confirm you see the CSRF token value being generated, AND submitted in your form request

    Original Response

    My guess is that you have the tag in the template but it’s not rendering anything (or did you mean you confirmed in the actual HTML that a CSRF token is being generated?)

    Either use RequestContext instead of a dictionary

    render_to_response("foo.html", RequestContext(request, {}))
    

    Or make sure you have django.core.context_processors.csrf in your CONTEXT_PROCESSORS setting.

    https://docs.djangoproject.com/en/dev/ref/contrib/csrf/

    Or add the token to your context manually

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is the first time i use django. I'm really a beginner. And this
Django advanced beginner here. I'm banging my head against the wall trying to figure
Absolute beginner question: I have a template file index.html that looks like this: ...
Beginner here: In this answer to my question of how to insert data into
Beginner here, I have a simple question. In Android what would be the best
Beginner in python, but been programming for about 5 years now. I suspect I
I know this sounds kind of stupid, but as a beginner in Django (and
Being a beginner of using Django, i am trying to add some module for
I am a Django beginner, and I want to make this tutorial as exercise:
Beginner programmer here. So bear with me. I have a simple python program. print

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.