协程和Django clickjacking中间件

时间:2018-07-16 05:13:41

标签: django django-views aiohttp django-middleware

我正在尝试将aiohttp库用于Django。我已按照本教程进行操作,但遇到以下错误,将我的view方法之一定义为async

Traceback (most recent call last):
  File "/Users/.../lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/Users/.../lib/python3.6/site-packages/django/utils/deprecation.py", line 97, in __call__
    response = self.process_response(request, response)
  File "/Users/.../lib/python3.6/site-packages/django/middleware/clickjacking.py", line 26, in process_response
    if response.get('X-Frame-Options') is not None:
AttributeError: 'coroutine' object has no attribute 'get'

我对此的最小工作示例如下:

async def conversion_form_process(request):
    if request.method == 'POST':
        form = ConversionForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            return HttpResponseRedirect('/thanks/')

    else:
        form = ConversionForm()

    return render(request, 'mainpage.html', {'form': form})

这表明它与async关键字有关,但我不知道如何解决。任何帮助深表感谢。谢谢!

1 个答案:

答案 0 :(得分:1)

对不起, aiohttp Django 不兼容。

它使用完全不同的范例。