我的网站使用Django 1.11.1和Django调试工具栏1.8在我的开发服务器(vagrant / gunicorn / nginx)上正常运行。我的常规测试套件运行正常。但是,当我告诉它运行硒测试时,它会以'djdt' is not a registered namespace error
消亡。我在网址,中间件和配置中都有相应的条目。如果我卷曲localhost,它将返回包含调试工具栏的主页。如果我将工具栏设置为不显示show_toolbar代码,我的selenium测试仍然会崩溃,但网站仍然正常(并且不显示调试工具栏)。
关于如何让我的硒测试运行的想法?
> python manage.py test ann.selenium
Creating test database for alias 'default'...
Installed 8 object(s) from 1 fixture(s)
Installed 3 object(s) from 1 fixture(s)
Installed 2 object(s) from 1 fixture(s)
Installed 16 object(s) from 7 fixture(s)
Installed 6 object(s) from 1 fixture(s)
Installed 1 object(s) from 1 fixture(s)
Adding auth tokens for the API...
System check identified no issues (0 silenced).
Internal Server Error: /
Traceback (most recent call last):
File "/home/vagrant/.virtualenvs/ann/lib/python3.5/site-packages/django/urls/base.py", line 77, in reverse
extra, resolver = resolver.namespace_dict[ns]
KeyError: 'djdt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/vagrant/.virtualenvs/ann/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/vagrant/.virtualenvs/ann/lib/python3.5/site-packages/django/utils/deprecation.py", line 142, in __call__
response = self.process_response(request, response)
File "/home/vagrant/.virtualenvs/ann/lib/python3.5/site-packages/debug_toolbar/middleware.py", line 134, in process_response
bits[-2] += toolbar.render_toolbar()
File "/home/vagrant/.virtualenvs/ann/lib/python3.5/site-packages/debug_toolbar/toolbar.py", line 64, in render_toolbar
return render_to_string('debug_toolbar/base.html', context)
File "/home/vagrant/.virtualenvs/ann/lib/python3.5/site-packages/django/template/loader.py", line 68, in render_to_string
return template.render(context, request)
File "/home/vagrant/.virtualenvs/ann/lib/python3.5/site-packages/django/template/backends/django.py", line 66, in render
return self.template.render(context)
File "/home/vagrant/.virtualenvs/ann/lib/python3.5/site-packages/django/template/base.py", line 207, in render
return self._render(context)
File "/home/vagrant/.virtualenvs/ann/lib/python3.5/site-packages/django/test/utils.py", line 107, in instrumented_test_render
return self.nodelist.render(context)
File "/home/vagrant/.virtualenvs/ann/lib/python3.5/site-packages/django/template/base.py", line 990, in render
bit = node.render_annotated(context)
File "/home/vagrant/.virtualenvs/ann/lib/python3.5/site-packages/django/template/base.py", line 957, in render_annotated
return self.render(context)
File "/home/vagrant/.virtualenvs/ann/lib/python3.5/site-packages/django/template/defaulttags.py", line 458, in render
url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
File "/home/vagrant/.virtualenvs/ann/lib/python3.5/site-packages/django/urls/base.py", line 87, in reverse
raise NoReverseMatch("%s is not a registered namespace" % key)
django.urls.exceptions.NoReverseMatch: 'djdt' is not a registered namespace
答案 0 :(得分:2)
显然答案是如果您正在进行硒测试,请不要加载django_debug_toolbar。
n
答案 1 :(得分:1)
如果你想看到django调试工具栏。 如果是django 1.11,那么请尝试下面的代码。替换"模式"用[](列表)。我在django-debug-toolbar 1.8中测试过
if settings.DEBUG:
import debug_toolbar
urlpatterns += [
url(r'^__debug__/', include(debug_toolbar.urls)),
]
请查看其他内容,如
DEBUG = True MIDDLEWARE_CLASSES =
[' debug_toolbar.middleware.DebugToolbarMiddleware',] INTERNAL_IPS =
[' 127.0.0.1',](相应地添加ip)