Login

Add CSRF token to templates

Author:
coleifer
Posted:
July 3, 2011
Language:
Shell
Version:
Not specified
Score:
1 (after 1 ratings)

Searches through templates, adding the {% csrf_token %} tag whenever it finds a form that posts.

1
2
3
find . -type f -name "*.html" -exec sed -i \
's|\(<form[^>]*method="post"[^>]*>\)\({% csrf_token %}\)\?|\1{% csrf_token %}|g' \
{} \;

More like this

  1. the steps of migration using south in Django... by lockys 9 years, 7 months ago
  2. One line SMTP sink server by Baguage 9 years, 8 months ago
  3. Virtualfish Hook by HubertGrzeskowiak 9 years, 9 months ago
  4. How to rename processes by diverman 12 years, 5 months ago

Comments

flipflop (on July 4, 2011):

That's very cool! I've been trying to do this for a while, without good results.

#

chriswedgwood (on May 28, 2020):

Great post, thanks!

#

Please login first before commenting.