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

  • SEARCH
  • Home
  • 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 9079315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:48:29+00:00 2026-06-16T19:48:29+00:00

Possible Duplicate: CSRF Protection in Django 1.4 I am trying to make a simple

  • 0

Possible Duplicate:
CSRF Protection in Django 1.4

I am trying to make a simple system for ticket reservation for rockets using Django. However, every time I try to reserve a ticket, I get the Forbidden 403 error: CSRF token missing or incorrect.

Here is my code:

models.py:

class Tickets(models.Model):
    rocket_line = models.ForeignKey('Rockets')
    date = models.DateField()
    number_of_seats = models.IntegerField()
    email = models.CharField(max_length=50)
    ordered_on = models.DateTimeField()
    total_price = models.DecimalField(max_digits=10, decimal_places=2)
    def __unicode__(self):
        return str(self.id)

views.py:

def order(request):
    if request.method == 'POST':
        order = Tickets(
            rocket_line = Rockets.objects.get(id=request.POST['rocket_line']),
            date=request.POST['date'],
            number_of_seats=request.POST['number_of_seats'],
            email=request.POST['email'],
            ordered_on=datetime.now(),
            total_price=(float(number_of_seats) * float(Rockets.objects.get(id=request.POST['rocket_line']).rprice))
        )
        order.save()
        return HttpResponseRedirect('/menu/')
    else:
        all_rockets = Rockets.objects.all().order_by('rtime')
        return render_to_response('order.html', { 'all_rockets': all_rockets},  RequestContext(request))

order.html:

<h1>You can order a ticket here:</h1>

        <form action="/order/" method="post">       
        <p>             
        <label>Rocket_line</label>
        <select name="rocket_line">
            {% for rocket in all_rockets %}
                <option value="{{ rocket.id }}">{{ rocket }}</option>
            {% endfor %}
        </select>
        <label>Date</label>
        <input name="date" value="YYYY-MM-DD" type="text" size="10" />
        <label>Number of seats</label>
        <input name="number_of_seats" value="" type="text" size="10" />
        <label>E-mail</label>
        <input name="email" value="@" type="text" size="50" />
        <br /><br />
        <input class="button" value="Order" type="submit" />        
        </p>        
        </form>             
    <br />

Could you help me to resolve, where the problem might be?

  • 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-16T19:48:30+00:00Added an answer on June 16, 2026 at 7:48 pm

    taken from the almighty django’s docs:

    Step 1:

    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.)

    Step 2:

    <form action="." method="post">{% csrf_token %}
    

    that {% csrf_token %} is all you need to add to your template.

    there’s other solutions around (decorators or ajax based) but this one is the fastest and most used (i think, at least… it requires no hassle whatsoever to be implemented)

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

Sidebar

Related Questions

Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: ImproperlyConfigured: Middleware module “django.middleware.csrf” does not define a “CsrfResponseMiddleware” class I am
Possible Duplicate: nth-child for every two table rows I'm trying to work my way
Possible Duplicate: "CSRF token missing or incorrect" while post parameter via AJAX in Django
Possible Duplicate: How to convert text to unicode code point like \u0054\u0068\u0069\u0073 using php?
Possible Duplicate: Does every Core Data Relationship have to have an Inverse? I have
Possible Duplicate: Understanding NSRunLoop Till now I know that every thread has its own
Possible Duplicate: Remove Datepicker Function dynamically In my web application i am using the
Possible Duplicate: MD5 algorithm in Objective C I need to hash a string using
Possible Duplicate: How do I create a nice-looking DMG for Mac OS X using

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.