资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

'url'requiresanon-emptyfirstargument.ThesyntaxchangedinDjango1.5,seethedocs

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

成都创新互联公司是一家专业提供麒麟企业网站建设,专注与成都网站设计、成都做网站、HTML5、小程序制作等业务。10年已为麒麟众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。

参考了stackoverflow里面的一个帖子

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

`post`.`title`

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"%}

经过测试的确如此。


名称栏目:'url'requiresanon-emptyfirstargument.ThesyntaxchangedinDjango1.5,seethedocs
网页网址:http://cdkjz.cn/article/jdojjh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220