fir3net

PPS-Firenetbanner-780.5x190-30-03-17

Django 1.5 - 'url' requires a non-empty first argument.

Issue

When running Django 1.5.1 you may observe the following error,

NoReverseMatch at /
'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs.

Solution

This issue can occur due to changes in the url tag syntax. More information on this can be found at  https://docs.djangoproject.com/en/dev/releases/1.5/.

The correct syntax for url tags can be found below, as you can see the view is now enclosed within quotes.

old - {% url project.app.views.main %}
new - {% url "project.app.views.main" %}

In instances where you are upgrading to Django 1.5.1, rather then manually amend all of your old templates the following sed command can be used to update your templates.

sed -i -r 's/url ([^"]+) %/url "\1" %/g' template.html

 

Tags: Django