nothing i can do about "CSRF token missing or incorect" -- beginner

20 views
Skip to first unread message

aseds

unread,
Sep 2, 2014, 3:57:13 AM9/2/14
to django...@googlegroups.com
i searched and tried what i found to solve it, but...
here is my edit.html which contains my form:

<!DOCTYPE html>
<html>
<head>
<title>{{ page_name }} - Editing</title>
</head>

<body>
<h1>Editing {{ page_name }}</h1>
<form method="post" action="/wikicamp/{{ page_name }}/save/">
{% csrf_token %}
<textarea name="content" rows="20" cols="60">{{ content }}</textarea>
<input type="submit" value="Save Page"/>
</form>
</body>

</html>

and here is my views.py:

# ...

def edit_page(request, page_name):
    try:
page = Page.objects.get(pk = page_name)
content = page.contents
except Page.DoesNotExist:
content = ""
return render(request, "edit.html", {"page_name": page_name, "content": content})

# ...


i changed my views.py as was suggested in a webpage to this:

@csrf_protect
def edit_page(request, page_name):
c = {}
try:
page = Page.objects.get(pk = page_name)
content = page.contents
except Page.DoesNotExist:
content = ""
return render(request, "edit.html", {"page_name": page_name, "content": content}, c)


but it didn't help.
thank you for your help.


François Schiettecatte

unread,
Sep 2, 2014, 7:55:11 AM9/2/14
to django...@googlegroups.com
Did you check that the csrf_token is actually inserted into the form by looking at the HTML in the browser?

François
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0acb15b8-6752-4930-8e72-c3c77ec9bd32%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

aseds

unread,
Sep 2, 2014, 8:03:44 AM9/2/14
to django...@googlegroups.com
it suddenly got solved. i don't know how but now it's working.
anyway i didn't know exactly what this CSRF do but thanks to you i now do know. thanks again..
Reply all
Reply to author
Forward
0 new messages