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

 

Rick Donato

Want to become a Django expert?

Here is our hand-picked selection of the best courses you can find online:
The Complete Web Development Bootcamp course
Django Practical Guide course
Django Full Stack Developer Bootcamp
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial