Django Reverse与参数'()'和关键字参数'{}'找不到 [英] Django Reverse with arguments '()' and keyword arguments '{}' not found

查看:433
本文介绍了Django Reverse与参数'()'和关键字参数'{}'找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个这样的网址格式:

 #mproject / myapp.urls.py 

url(r'^ project /(?P< project_id> \d +)/ $','user_profile.views.EditProject ',name ='edit_project'),

它在浏览器中正常工作,但是在我进行测试时在shell中执行此操作:

  from django.test import Client 
from django.core.urlresolvers import reverse

client = Client()
response = client.get(reverse('edit_project'),project_id = 4)

我感到恐惧:

  NoReverseMatch:反向'edit_project' ()'和关键字参数'{}'未找到。 

我在这里缺少什么?

解决方案

您必须指定 project_id

  reverse('edit_project',kwargs = {'project_id':4})

文件 here


Hi I have an infuriating problem.

I have a url pattern like this:

# mproject/myapp.urls.py

url(r'^project/(?P<project_id>\d+)/$','user_profile.views.EditProject',name='edit_project'),

it works fine in the browser but for testing, when I do this in the shell:

from django.test import Client
from django.core.urlresolvers import reverse

client= Client()
response = client.get(reverse('edit_project'), project_id=4)

I get the dreaded:

NoReverseMatch: Reverse for 'edit_project' with arguments '()' and keyword arguments '{}' not found.

What am I missing here?

解决方案

You have to specify project_id:

reverse('edit_project', kwargs={'project_id':4})

Doc here

这篇关于Django Reverse与参数'()'和关键字参数'{}'找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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