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 7724767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:46:14+00:00 2026-06-01T04:46:14+00:00

the djangobook has this section To activate this CSRF protection, add ‘django.contrib.csrf.middleware.CsrfMiddleware’ to the

  • 0

the djangobook has this section

To activate this CSRF protection, add
‘django.contrib.csrf.middleware.CsrfMiddleware’ to the
MIDDLEWARE_CLASSES setting in your settings file. This middleware
needs to process the response after SessionMiddleware, so
CsrfMiddleware must appear before SessionMiddleware in the list
(because the response middleware is processed last-to-first).

however ,djangoproject page tells it different

MIDDLEWARE_CLASSES = (
‘django.middleware.common.CommonMiddleware’,
‘django.contrib.sessions.middleware.SessionMiddleware’,
‘django.middleware.csrf.CsrfViewMiddleware’,
‘django.contrib.auth.middleware.AuthenticationMiddleware’,
‘django.contrib.messages.middleware.MessageMiddleware’, )

It is a bit confusing..Do the CsrfViewMiddleware process the response after SessionMiddleware now?Can someone clarify?

  • 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-06-01T04:46:16+00:00Added an answer on June 1, 2026 at 4:46 am

    From the Django docs:

    Add the middleware ‘django.middleware.csrf.CsrfViewMiddleware’ to your
    list of middleware classes, MIDDLEWARE_CLASSES. (It should come before
    any view middleware that assume that CSRF attacks have been dealt
    with.)

    Source: https://docs.djangoproject.com/en/1.4/ref/contrib/csrf/#how-csrf-works

    Here’s my Middleware list in a freshly generated Django project (1.3.1):

    MIDDLEWARE_CLASSES = (
        'django.middleware.common.CommonMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
    )
    

    So, yes, Django processes the CSRF Middleware after the session middleware now.

    The Django Book is severely outdated – I wouldn’t use it as a resource for learning Django these days. The Django tutorial, on the other hand, is a wonderful resource.

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

Sidebar

Related Questions

while reading up djangobook chapter ,I came across the section which mentions a csrf
So I'm learning Django (1, 3, 1, 'final', 0) through this resource: http://www.djangobook.com/en/2.0/chapter05/ I
If you want to store extra information about a user (django.contrib.auth.models.User) in Django you
The Django Book has a neat content publishing template. Anyone knows if it's available
I use the method defined in django documentaion:http://www.djangobook.com/en/beta/chapter12/ def login(request): m = members.get_object(username__exact=request.POST['username']) if
I'm just learning Django and trying to setup the View and URLconfs ( http://djangobook.com/en/2.0/chapter03/
In the process of learning Django and Python. I can't make sense of this.
I exported the path of my django project by $ export DJANGO_SETTINGS_MODULE=/Users/masi/Documents/Test/djangobook/ch3.settings I run
So, i'm studying the Django Book, and django documentation, and I can't understand this
I used nginx and uwsgi for djangobook.ir and I have this problem. any request

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.