Django' dict'对象没有属性' set_cookie'

时间:2017-09-06 03:57:07

标签: django

浏览器发送OPTIONS请求,我得到了这个奇怪的错误。有什么可能错的?测试了django 1.10和1.11

ERROR Internal Server Error: /cc_login/
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/utils/decorators.py", line 167, in _wrapped_view
    return middleware.process_response(request, response)
  File "/usr/local/lib/python3.5/dist-packages/django/middleware/csrf.py", line 328, in process_response
    self._set_token(request, response)
  File "/usr/local/lib/python3.5/dist-packages/django/middleware/csrf.py", line 192, in _set_token
    response.set_cookie(
AttributeError: 'dict' object has no attribute 'set_cookie'
[06/Sep/2017 10:50:45] "OPTIONS /cc_login/ HTTP/1.1" 500 12601

``` 根据要求:

MIDDLEWARE_CLASSES = (
    'cluster.templatetags.ranges.RangeMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'cluster.templatetags.middleware.LastSeenMiddleware',
    'django.middleware.gzip.GZipMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

```

1 个答案:

答案 0 :(得分:0)

我认为请求仍然在django中,但它到达了无法处理OPTIONS的请求处理程序