[Answer]-Django 1.6 "CSRF verification failed. Request aborted."

0๐Ÿ‘

โœ…

I fixed this issue by using RequestContext instead of Context:

def login(request):
  if request.method == "POST":
    return render(request, 'login.tpl')
  elif request.method == "GET":
    # Prepare templates
    header = get_template("header.tpl")
    body = get_template("login.tpl")
    footer = get_template("footer.tpl")

    html = header.render(RequestContext(request, {"title": "Login", "charset": "UTF-8"}))
    html = html + body.render(RequestContext(request, {}))
    html = html + footer.render(Context({}))

    return HttpResponse(html)
๐Ÿ‘คuser1529891

1๐Ÿ‘

You are missing the return. The view is a function and expects you to return an HTTPResponse object.

render_to_response('list.tpl', context_instance=RequestContext(request))

should be

return render_to_response('list.tpl', context_instance=RequestContext(request))

Another thing,

if request.POST

should be

if request.method == 'POST'

Moreover, Avoid using render_to_response. Instead, use render. Source

return render(request, 'list.tpl')
๐Ÿ‘คRod Xavier

Leave a comment