Pie*_*las 1 python testing django
我正在尝试为一些仅在调试中设置的 URL 设置测试。它们没有设置,因为显然我的设置文件和 urls.py 之间的 DEBUG 值更改为 False。我以前从未遇到过这个问题,而且我不记得做过任何涉及 DEBUG 值的特别花哨的事情。
这是我的 urls.py :
from django.conf import settings
from my_views import dnfp
print "settings.DEBUG in url: {}".format(settings.DEBUG)
if settings.DEBUG:
    urlpatterns += [url(r'^dnfp/$', dnfp, name="debug_not_found_page"...
Run Code Online (Sandbox Code Playgroud)
这是我的设置文件:
DEBUG=True
print "DEBUG at the end of the settings: {}".format(DEBUG)
Run Code Online (Sandbox Code Playgroud)
在我的测试中失败的内容:
 reverse("debug_not_found_page"), 
Run Code Online (Sandbox Code Playgroud)
这是测试的输出:
DEBUG at the end of the settings: True
settings.DEBUG in url: False
Creating test database for alias 'default'...
.E
(...)
NoReverseMatch: Reverse for 'debug_not_found_page' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Run Code Online (Sandbox Code Playgroud)
如果我自己更改 urls.py 中的值,则会再次设置 url,并且测试将使用此 urls.py :
from django.conf import settings
from my_views import dnfp
settings.DEBUG = True
if settings.DEBUG:
    urlpatterns += [url(r'^dnfp/$', dnfp, name="debug_not_found_page"...
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?我的 DEBUG 值何时以及为何在设置和 url 之间发生变化?
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           1653 次  |  
        
|   最近记录:  |