中间件中的reverse()调用在测试中失败

时间:2013-09-06 19:23:57

标签: python django

每当我尝试在中间件中使用reverse()时,在运行测试manage.py test时会出现错误,并出现此错误

File "C:\Python27\lib\site-packages\django\core\urlresolvers.py", line 416, in _reverse_with_prefix
"arguments '%s' not found." % (lookup_view_s, args, kwargs))
NoReverseMatch: Reverse for 'home' with arguments '()' and keyword arguments '{}' not found.

middleware.py

from django.core.urlresolvers import reverse

class TestMid (object):
def process_request(self, request):
    target = reverse('home_custom')

urls.py

from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
    url(r'^$', 'test_django.views.home', name='home_custom'),
)

views.py

from django.http.response import HttpResponse
from django.core.urlresolvers import reverse
def home(request):
    return HttpResponse('path to page %s' % reverse('home_custom'))

我没有写任何测试。我只是运行Django附带的测试。

这看起来像是一个类似于NoReverseMatch error when running tests in Django的问题,但这个问题没有得到回答。

Django 1.5.1和1.5.2

0 个答案:

没有答案