我收到以下错误消息:
Reverse for 'code_front' with arguments '()' and keyword arguments '{'category_slug': u'code'}' not found.
我是新来的,请帮忙.
Gui*_*ert 10
您收到的错误是因为您的urls.py中没有匹配您正在使用的视图和参数.
一个例子:
如果你的urls.py看起来像这样:
urlpatterns = patterns('',
url(r'^YOUR_PATTERN/(?P<PARAMETER>.*)', your_view, name='code_front'),
)
Run Code Online (Sandbox Code Playgroud)
你可以像这样反转它的网址:
在模板中:
直接使用值:
{% url code_front 'some_value' %}
您可以将变量用作参数值:
{% url code_front variable %}
使用多个参数(如果您需要它们):
{% url code_front variable, another_variable %}
或者使用命名参数:
{% url code_front parameter=variable %}
你可以在你的python代码中完成同样的事情:
reverse('code\_front', args=['some_value'])reverse('code\_front', args=[variable])reverse('code\_front', args=[variable, another_variable])reverse('code\_front', kwargs={'parameter': variable})您需要导入该reverse功能:
from django.core.urlresolvers import reverse
| 归档时间: |
|
| 查看次数: |
4874 次 |
| 最近记录: |