I get Forbidden (403) CSRF verification failed. Request aborted. When I submit the form on the home.html page...
I have no idea why because I have the {% csrf_token %} in the form,
I have the right settings
I am using context_instance=RequestContext(request)
This is the form (it is in home.html):
<form method="post" action="/schedule/" >
{% csrf_token %}
<input type="text" name="course1" value="" maxlength="100" />
<input type="text" name="course2" value="" maxlength="100" />
<input type="text" name="course3" value="" maxlength="100" />
<input type="text" name="course4" value="" maxlength="100" />
<input type="text" name="course5" value="" maxlength="100" />
<input type="text" name="course6" value="" maxlength="100" />
<br />
<button type="submit" id="submit">Submit</button>
</form>
This are my views:
from django.shortcuts import render_to_response, redirect
import requests
from bs4 import BeautifulSoup
from . import AllClasses
from django.template.context_processors import csrf
from django.template import RequestContext
import datetime
def home(request):
return render_to_response("src/home.html", {}, context_instance=RequestContext(request))
# Create your views here.
def schedule(request):
c = {}
subjects = []
courses = []
if request.method == 'POST':
subjects[0] = request.POST['course1']
subjects[1] = request.POST['course2']
subjects[2] = request.POST['course3']
subjects[3] = request.POST['course4']
subjects[4] = request.POST['course5']
subjects[5] = request.POST['course6']
for subject in subjects:
courses.append(Course.objects.filter(subject=subject))
c.update({'courses_inputed': courses})
return render_to_response("src/weekataglancetest.html", c, context_instance=RequestContext(request))
This is in settings.py
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
Please help I've been stuck on this for so long!
Thanks very much everyone!