Apr 04 2013

Django 1.5 migrating to new url tag syntax

published by Iurii Garmash
in blog Programmer blog
original entryDjango 1.5 migrating to new url tag syntax

bash command django migrating migration python snippet snippets tag templates templatetag upgrade url

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. http://djangosnippets.org/snippets/2905/

Tag cloud

Social Sharing