Tuesday, September 2, 2014

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

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.


--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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.

No comments:

Post a Comment