我越來越想呈現模板時,出現以下錯誤:Django的無反向匹配錯誤 - 模板渲染
NoReverseMatch at /things/
Reverse for 'edit_things' with arguments '(u'<function generate at 0x10a970aa',)' and
keyword arguments '{}' not found.
在我的模板,以下工作:
<a href="{% url add_thing %}" class="btn_plus">
但後來我在這裏得到一個錯誤:
<td onclick="document.location = '{% url edit_thing thing.guid %}';" class="edit" id="edit_thing_{{ forloop.counter }}"> </td>
我們不會使用: {從未來%%負載URL}。這是Django 1.4。
在我的網址:
url(r'^edit_thing/(?P<thing_id>[\w_-]{1,32})/$', 'edit_thing', name='edit_thing'),
和視圖的樣子:
def edit_thing(request, thing_id):
上什麼錯誤任何想法?我不明白爲什麼add_things可以在模板中正常工作,並且只要edit_thing就會崩潰。是否edit_thing需要一個參數?我已經嘗試了Stackoverflow上的所有內容,並嘗試了各種組合(包括未來的加載url等等)。
這裏是我的模型:
class Thing(models.Model):
guid = models.CharField(max_length=Guid.LENGTH, blank=True, null=True, unique=True, default=Guid.generate)
class Meta:
app_label = 'things'
你有沒有試過'{%url things:edit_thing thing.guid%}'? (假設你的應用名稱實際上是「東西」) –
你可以粘貼你的事物模型嗎?另外,嘗試{%url edit_thing thing_id = thing.guid%} – msc
好吧,所以我嘗試了{%url things:edit_thing thing.guid%},並解決了這個問題。 現在我得到的問題是: 'u'things'不是註冊的命名空間。我在'INSTALLED_APPS'中有'東西'。 – Konrad