我是新来的django-1.6。当我使用DEBUG = True运行django服务器时,它运行得非常完美。但是,当我在设置文件中将DEBUG更改为False时,服务器停止,并在命令提示符上给出以下错误:
CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.
在我将ALLOWED_HOSTS更改为["http://127.0.0.1:8000",]之后,在浏览器中我得到了错误:
Bad Request (400)
在没有调试模式的情况下可以运行Django吗?
我在我的生产cms中有一个小问题。其中一页(大约有50页)拒绝发布。我的意思是:如果我点击管理界面中的“发布”或者使用publish_page方法,我不会得到任何错误。在页面列表视图中,此页面旁边有一个绿色的复选标记。但是当我在那里浏览时,我得到了一个很好的404错误。如果我刷新页面列表视图,绿色的复选标记会变成红色标记(未发布)。
我不知道我应该从哪里开始调试这个问题。
>>> from cms.api import publish_page
>>> p = Page.objects.get(pk__exact=66)
>>> r = U
我的Django-Debug-Toolbar一单击面板(如“请求”)就会产生一个Http404。我检查了我的配置多次,但没有发现什么问题。
版本:
django-调试-工具栏== 1.8
django == 1.11.1
settings.py
# DEBUG TOOLBAR
if DEBUG:
def custom_show_toolbar(request):
""" Only show the debug toolbar to users with the superuser flag. """
我为我的Django项目定义了错误400和404的自定义模板。当我尝试访问我的站点的生产版本时,错误404模板正确加载了缺少的页面。但是,如果我向Apache/Django服务器(例如http://mysite.example.com/%)发送了一个错误请求,则错误400的模板不会被加载,而是呈现常规的Apache错误页面:
Bad Request
Your browser sent a request that this server could not understand.
Apache/2.4.18 (Ubuntu) Server at mysite.example.com Port
在我的一个观点中,我有一个代码:
raise Http404
当DEBUG=False Django呈现模板500.html而不是正确的404.html时!我不明白为什么!
编辑:当DEBUG=True我得到标准的一个(由Django)
Page not Found (404)
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
更重要的
当我设置debug = false时,我遇到了"Bad Request 400“(生产服务器)问题。我使用cookiecutter和Django 1.8。我设置了ALLOWED_HOSTS = ['*'] --没有任何结果。
在日志中,我有一条消息:
Invalid HTTP_HOST header: 'myaddress.here'. You may need to add 'myaddress.here' to ALLOWED_HOSTS.
我尝试了文档django中的代码,也没有成功:
'handlers': {
当我访问运行Django 1.6的生产网站时,我想查看Django Debug Toolbar。我的服务器运行的是Debian 7.8、Nginx 1.2.1和Gunicorn 19.1.1。但是,在将DDT添加到已安装的应用程序后,当我尝试访问该站点时,我收到以下错误:
NoReverseMatch at /
u'djdt' is not a registered namespace
Exception Location: /home/mysite/venv/mysite/local/lib/python2.7/site-packages/django/core/urlres
我的代码将返回上一次调用中的值,而不是空字符串。我怎么才能解决这个问题?
模板标签:
from django.template import Library, Node, resolve_variable
from django.utils.safestring import SafeText
from django.http import QueryDict
register = Library()
"""
The tag generates a parameter string in form '?param1=val1¶m2=val2&
我使用的是Django 1.6.5,设置如下:
DEBUG = True
当我切换到DEBUG = False并运行manage.py runserver时,我得到以下错误:
CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False
使用以下设置时,我得到了相同的错误:
ALLOWED_HOSTS = ['127.0.0.1', 'localhost']
我该如何解决这个问题呢?