After successfully upgrade my Django app from using Django 1.3 to Django 1.4, now i try to upgrade my app to be running Django 1.5.5
Some method i use are :
+ OS Debian 7
+ Python 2.7
+ Virtualenv
Django 1.5.5 released around October 2013. Here are the Official Release Notes
The deprecated feature was the new way of handling url in template.
What i got was the project template still the same with Django 1.4.10 .
After running I got bumped with deprecated feature which is url "new style" usage.
So before i use this :
{% url public_detail_billboard object.slug %}
It will give error :
'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs.
So we need to change it to :
{% url "public_detail_billboard" object.slug %}
Lucky for me, my application only breaks in the url method in the template. But the url all over the template. so i need to update the url to add some " " .
But we can do some faster thing with this, we are programmer right?
we can use sed to the rescue, here are the sed command which will do your job :
find . -type f -print0 | xargs -0 sed -i 's/{% url \([^" >][^ >]*\)/{% url "\1"/g'
That will change your file from :
{% url something.else ass bas %}
to this one :
{% url "something.else" ass bas %}
And now my application can run in Django 1.5.5
Some additional info, i upgrade some of my tools which supported in Django 1.5.5, which are :
+ Django Debug Toolbar 1.0.1
Some warning if you upgrade to Django 1.5.5, your app won't work in Django 1.3, which the url problem we have here.
But to make it still work in Django 1.3.x you must add
{% load url from future %}
in the Template.
So the most annoying job will be change your url to using "urlname" to all you html. If you practice reusable code, cannot imagine how many url you will be added in html. Remember using the sed command.
So to old code compatible with Django 1.3 remember :
1. Add {% load url from future %} in your template using url
2. Always use {% url "urlname" %} in your template after Django 1.5.5
Hope this helps you which planning to migrate to newer Django Release.
1 comments:
you can also add the following in your settings, so you don't need to load url in templates. This way once migrated, you'll only need to comment out lines on settings.
import django.template
django.template.add_to_builtins('django.templatetags.future')
Post a Comment