Django Newbie:“反向未找到” [英] Django Newbie : "Reverse not found"

查看:102
本文介绍了Django Newbie:“反向未找到”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一行Django表单:

  {%for aa in my_array%} 

似乎触发了此错误:


模板错误



呈现时捕获异常:
反向
'dev_env.profiles.views.viewPlan'with
参数'('',)'和关键字
参数'{}'找不到。


真的意思是



我怀疑这行是正确的,但错误信息是错误的。或者错误是真实的,但这行是一个红色的鲱鱼。



我应该在寻找什么?



更新: >

事实上,我有一个$ {code> {%url viewPlan planId%} 几行(所以报告的错误行是错误),但是在这种情况下,planId为空,错误被触发。

解决方案

你有一个名为 viewPlan ,您可以在模板中执行此操作:

  {%url viewPlan %} 

或视图中的类似内容:

  reverse('viewPlan')

如果你这样做,你没有这样的行:

  url(r'^ whatever / url / $' 'dev_env.profiles.views.viewPlan',name =viewPlan),

... in你的url配置我会想象这是你得到的错误。或者,更有可能的是,您可能会在viewPlan URL中捕获一个值(可能是id或某些东西),但在反转网址时不会传递参数。因此,如果您正在捕获正则表达式中的任何值,如下所示:

  url(r'^ plans /(\d + $','dev_env.profiles.views.viewPlan',name =viewPlan),

你需要这样调用:

  {%url viewPlan 15%} 
/ pre>

或像这样:

  reverse('viewPlan' ,args = [15]); 

其中 15 显然是捕获的值期待。


I have a line in a Django form :

{% for aa in my_array %}

which seems to be triggering this error :

Template error

Caught an exception while rendering: Reverse for 'dev_env.profiles.views.viewPlan' with arguments '('',)' and keyword arguments '{}' not found.

What does this error message really mean?

I suspect that either the line is correct, but the error message is wrong. Or the error is real but this line is a red-herring.

What on earth should I be looking for?

Update : Paulo sorted this, below.

In fact, I had a {% url viewPlan planId %} a couple of lines away (so the reported error line was wrong), but the error was triggered because planId was empty in this case.

解决方案

Do you have a view named viewPlan with which you do something like this in a template:

{% url viewPlan %}

or something like this in a view:

reverse('viewPlan')

If you do that and you do not have a line that looks like this:

url(r'^whatever/url/$', 'dev_env.profiles.views.viewPlan', name="viewPlan"),

...in your url configuration I would imagine that's the error you're getting. Alternatively, and more likely, you are probably capturing a value (maybe id or something) in the viewPlan URL but are not passing an argument when reversing the url. So if you are capturing any values in the regex, like this:

url(r'^plans/(\d+)$', 'dev_env.profiles.views.viewPlan', name="viewPlan"),

You need to call it like this:

{% url viewPlan 15 %}

Or like this:

reverse('viewPlan', args=[15]);

Where 15 is obviously whatever the captured value is expecting.

这篇关于Django Newbie:“反向未找到”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆