Skip to content

Instantly share code, notes, and snippets.

@mgrouchy
Created August 3, 2012 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgrouchy/3252725 to your computer and use it in GitHub Desktop.
Save mgrouchy/3252725 to your computer and use it in GitHub Desktop.
csrf
from django.shortcuts import render
def view(request):
form = FormClass()
return render(request, 'formpage.html', RequestContext(request, {'form': form}))
<html>
<head>
</head>
<body>
<form action="{% url some.view.here %}" method="post">
{% csrf_token %}
{{ form.as_p }}
</form>
</body>
</html>
{% comment %}
- You must render this view with a form(for variable form)
- View must be rendered using RequestContext
- You must have django.middleware.csrf.CsrfViewMiddleware middleware in your Middleware settings
{% endcomment %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment