Django運行時出現'url' requires a non-empty first argument的解決辦法:python
參考了stackoverflow裏面的一個帖子ide
I started using Django release 1.5 and got a problem with my old code: <a href="{% url auto.views.viewpost post.slug %}"><h3>`post`.`title`</h3></a> Error: 'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs. Docs: One deprecated feature worth noting is the shift to 「new-style」 url tag. Prior to Django 1.3, syntax like {% url myview %} was interpreted incorrectly (Django considered "myview" to be a literal name of a view, not a template variable named myview). Django 1.3 and above introduced the {% load url from future %} syntax to bring in the corrected behavior where myview was seen as a variable. The upshot of this is that if you are not using {% load url from future %} in your templates, you’ll need to change tags like {% url myview %} to {% url "myview" %}. If you were using {% load url from future %} you can simply remove that line under Django 1.5 #該代碼片斷來自於: http://www.sharejs.com/codes/python/7007
大概意思就是說:原來寫成:{%url myview%} 這樣的語句在1.5之前的版本是能夠經過的,
更換到1.5的版本之後要寫成:{%url "myview"%}
通過測試的確如此。
post