2013-03-23 39 views
2

我不得不改變我的模板稍微做一些URL重定向,所以我用:如何使用url標籤下的腳本標籤

<script> 
    if window.location="www.somesite.com"{ 
     window.location="www.someothersite.com{% url app.views.some_view argument %}" 
    } 
</script> 

但我不斷收到錯誤NoReverseMatch: Reverse for 'app.views.some_view' with arguments 'xxx' and keyword arguments '{}' not found.

我我使用{% load url from future%},我確信那個特定的鏈接工作正常,否則沒有Javascript。

+1

您的反向參數應該用引號括起來,如[here]所示(https://docs.djangoproject.com/en/dev/ref/templates/builtins/#std:templatetag-url)。 – ersran9 2013-03-23 20:40:55

回答

0

我認爲你需要把你周圍的視圖名稱報價:

{% url "app.views.some_view" argument %} 

這是新的語法從Django 1.5開始。

+0

不,如果引號是問題(在Django 1.5中),那麼錯誤信息就是:''url'需要一個非空的第一個參數。 Django 1.5中的語法發生了變化,請參閱文檔。因此,看起來OP正在使用Django的早期版本。 – janos 2013-06-04 22:02:23

0

問題在於您的查看方法app.views.some_view與模板中的調用之間的參數數量不匹配。

如果你可以粘貼你認爲有用的視圖方法的簽名。你寫你的模板代碼的方式,它表明的觀點方法簽名應該是這樣的:

def some_view(request, arg): 
    pass 

如果這已經是這樣了,然後檢查什麼是真正的argument在模板中的價值。剛打印的測試,像這樣:

HERE: {{ argument }} END 

單從崗位目前尚不清楚是否argument是一個變量或模板的字符串。