溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

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

發(fā)布時(shí)間:2020-07-08 12:50:42 來源:網(wǎng)絡(luò) 閱讀:516 作者:redapple2008 欄目:軟件技術(shù)

Django運(yùn)行時(shí)出現(xiàn)'url' requires a non-empty first argument的解決辦法:

參考了stackoverflow里面的一個(gè)帖子

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%} 這樣的語(yǔ)句在1.5以前的版本是可以通過的,
更換到1.5的版本以后要寫成:{%url "myview"%}

經(jīng)過測(cè)試的確如此。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI