Django 1.5 migrating to new url tag syntax

Django 1.5 changed. The url tag syntax from {% url  my_page %} into {% url "my_page" %}. Now all my templates should be changed accordingly to migrate to 1.5. You could do it with executing this command in your bash shell.
Assuming you are in the project folder. Assuming you have version control, or do know how to backup your work ;). Some people claim it is unsafe. But you may want to make it safer with adding '{%' to the beginning of the string. To make sure only templates arre changed. Or either execute this only in your templates folder to be sure.
$ find . -type f -print0 | xargs -0 sed -i 's/ url \([^" >][^ >]*\)/ url "\1"/g'
And one person did a django snippet for this operation. You may also find it useful.


Post a Comment

Popular posts from this blog

Run Flask with Debug in PyCharm

Python converting PDF to Image

Django: Resetting Passwords (with internal tools)