使用python3在Django 2.x中的get_wsgi_application()中键入Error [英] Type Error in get_wsgi_application() in Django 2.x with python3

查看:426
本文介绍了使用python3在Django 2.x中的get_wsgi_application()中键入Error的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Web应用程序从Django 1.9迁移到2.0.2。
代码是

I am migrating a web application from Django 1.9 to 2.0.2. The code is

import os
import sys

path = '/mypath'
if path not in sys.path:
    sys.path.append(path)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Myapplication.settings")


from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

但是,如果尝试执行此操作,则会收到错误消息:

However, if I try to execute this, I get an error:

File "/home/.../wsgi.py", line 29, in <module>
application = get_wsgi_application()
File "/home/.../virtual/lagerthree/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
return WSGIHandler()
File "/home/.../lagerthree/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 140, in __init__
self.load_middleware()
File "/home/.../virtual/lagerthree/lib/python3.5/site-packages/django/core/handlers/base.py", line 39, in load_middleware
mw_instance = middleware(handler)
TypeError: object() takes no parameters

根据StackExchange和其他站点,此错误的原因是某些东西从1.x弃用到2.x,解决方案是 MiddlewareMixin 应该是像这样使用: class FOOMiddleware(MiddlewareMixin):...

According to StackExchange and other sites, the cause of this error is the deprecation of certain things from 1.x to 2.x and the solution is the MiddlewareMixin which should be used like this: class FOOMiddleware(MiddlewareMixin): ...

我的 MIDDLEWARE 设置为:

MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'reversion.middleware.RevisionMiddleware',
# Uncomment the next line for simple clickjacking protection:
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'users.middleware.TimezoneMiddleware')

但是我没有任何类,而且 get_wsgi_application()函数应该仍然有效,据我所知。

我应如何解决?

But I don't have any classes and also, the get_wsgi_application() function should still work, as far as I know.
How should I solve this?

推荐答案

也许是因为debug_toolbar ,作为唯一的第三方库。
无论如何,请尝试将django_debug_toolbar更新为最新版本。

Maybe it's because of the debug_toolbar, as the only one third-party library. Anyway , try to update django_debug_toolbar to lastest version.

这篇关于使用python3在Django 2.x中的get_wsgi_application()中键入Error的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆