温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-07-08 12:50:42 来源:网络 阅读:504 作者:redapple2008 栏目:软件技术

Django运行时出现'url' requires a non-empty first argument的解决办法:

参考了stackoverflow里面的一个帖子

I started using Django release 1.5 and got a problem with my old code:

<a href="{% url auto.views.viewpost post.slug %}"><h4>`post`.`title`</h4></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"%}

经过测试的确如此。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI