【问题标题】:Getting Django error with Debug False on django 1.7在 Django 1.7 上使用 Debug False 获取 Django 错误
【发布时间】:2015-01-05 05:43:47
【问题描述】:

我有 Django 1.7,当我向 django 提交 POST 请求时,我不断收到此错误。

如果 Debug 为真,那么我不会收到任何错误。

我已经看过了

Setting DEBUG = False causes 500 Error

我在ALLOWED_HOST 中添加了所有地址,但一直出错

[Django] ERROR (EXTERNAL IP): Internal Server Error:

    Internal Server Error: /api/user/edit
    Traceback (most recent call last):
     File "/srv/vhosts/site1/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 204, in get_response
       response = middleware_method(request, response)
     File "/srv/vhosts/site1/env/local/lib/python2.7/site-packages/htmlmin/middleware.py", line 41, in process_response
       if minify and self.can_minify_response(request, response):
     File "/srv/vhosts/site1/env/local/lib/python2.7/site-packages/htmlmin/middleware.py", line 32, in can_minify_response
       resp_ok = resp_ok and 'text/html' in response['Content-Type']
     File "/srv/vhosts/site1/env/local/lib/python2.7/site-packages/django/http/response.py", line 187, in __getitem__
       return self._headers[header.lower()][1]
    KeyError: 'content-type'

    Request repr(): 
    <WSGIRequest
    path://api/user/edit,
    GET:<QueryDict: {}>,
    POST:<QueryDict: {}>,
    COOKIES:{'csrftoken': 'HN2zP9edr2ItI5uW6tMocemUBczPiN4C',
    'sessionid': 'y10w8jqqertztttrol63bqtjfj8qa4c6'},
    META:{'CONTENT_LENGTH': '37',
    'CONTENT_TYPE': 'application/json;charset=UTF-8',
    u'CSRF_COOKIE': u'HN2zP9edr2ItI5uW6tMocemUBczPiN4C',
    'HTTP_ACCEPT': 'application/json, text/plain, */*',
    'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
    'HTTP_ACCEPT_LANGUAGE': 'en-GB,en-US;q=0.8,en;q=0.6',
    'HTTP_CONNECTION': 'close',
    'HTTP_COOKIE': 'sessionid=y10w8jqqertztttrol63bqtjfj8qa4c6; csrftoken=HN2zP9edr2ItI5uW6tMocemUBczPiN4C',
    'HTTP_HOST': '104.60.4.102',
    'HTTP_ORIGIN': 'https://104.60.4.102,
    'HTTP_REFERER': 'https://104.60.4.102/users/',
    'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36',
    'HTTP_X_CSRFTOKEN': 'HN2zP9edr2ItI5uW6tMocemUBczPiN4C',
    'HTTP_X_FORWARDED_FOR': '104.60.4.160',
    'PATH_INFO': u'//api/user/edit',
    'QUERY_STRING': '',
    'RAW_URI': '/api/user/edit',
    'REMOTE_ADDR': '',
    'REQUEST_METHOD': 'POST',
    'SCRIPT_NAME': u'',
    'SERVER_NAME': '104.60.4.102',
    'SERVER_PORT': '80',
    'SERVER_PROTOCOL': 'HTTP/1.0',
    'SERVER_SOFTWARE': 'gunicorn/19.0.0',
    'gunicorn.socket': <socket._socketobject object at 0x5daa910>,
    'wsgi.errors': <gunicorn.http.wsgi.WSGIErrorsWraper object at 0x5dbae10>,
    'wsgi.file_wrapper': <class 'gunicorn.http.wsgi.FileWrapper'>,
    'wsgi.input': <gunicorn.http.body.Body object at 0x5dbaf10>,
    'wsgi.multiprocess': True,
    'wsgi.multithread': False,
    'wsgi.run_once': False,
    'wsgi.url_scheme': 'http',
    'wsgi.version': (1, 0)}>

REMOTE_ADDR 以 '' 的形式出现,如果这可能是问题的话

数据可以很好地发布到数据库,但我在 firebug 中遇到了这个错误

【问题讨论】:

    标签: python django django-1.7


    【解决方案1】:

    Django-HTMLMin 似乎期望密钥 content-type 应该以大写字母开头。

    所以看看你是否自己设置了标题content-type,如果是,请更改为Content-Type

    我在存储库中为您快速搜索了Django HTMLMIN repo

    【讨论】:

    • 感谢您的帮助。我没有设置内容类型。我正在使用 django 休息框架。不知道它在哪里设置
    猜你喜欢
    • 2017-01-20
    • 2020-04-07
    • 2021-11-03
    • 2018-04-16
    • 2021-08-13
    • 2021-11-05
    • 1970-01-01
    • 1970-01-01
    • 2012-07-15
    相关资源
    最近更新 更多