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

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

问题描述

我有一行 Django 形式:

I have a line in a Django form :

{% for aa in my_array %}

这似乎触发了这个错误:

which seems to be triggering this error :

模板错误

渲染时发现异常:反转为'dev_env.profiles.views.viewPlan' 与参数 '('',)' 和关键字未找到参数{}".

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.

我到底应该寻找什么?

更新:Paulo 在下面对此进行了排序.

Update : Paulo sorted this, below.

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

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.

推荐答案

您是否有一个名为 viewPlan 的视图,您可以使用它在模板中执行以下操作:

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

{% url viewPlan %}

或视图中的类似内容:

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"),

...在您的 url 配置中,我想这就是您遇到的错误.或者,更有可能的是,您可能正在 viewPlan URL 中捕获一个值(可能是 id 或其他东西),但在反转 url 时没有传递参数.因此,如果您在正则表达式中捕获任何值,如下所示:

...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"),

你需要这样称呼它:

{% url viewPlan 15 %}

或者像这样:

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

其中 15 显然是所期望的捕获值.

Where 15 is obviously whatever the captured value is expecting.

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

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