在 Django 1.7 上使用 Debug False 获取 Django 错误

Getting Django error with Debug False on django 1.7

我有 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 中收到该错误

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

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

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