嗨,我刚运行python -Wa manage.py test
时更新了几个软件包(包括django),没有发现问题,但是当我运行服务器时出现错误,我找不到它的来源。
我正在使用Django 3.0.4和python 3.6
堆栈跟踪:
"D:\Program Files (x86)\Jetbrains\apps\PyCharm-P\ch-0\193.6494.30\bin\runnerw64.exe" D:\Projects\coursemanager\backend\venv\Scripts\python.exe D:/Projects/coursemanager/backend/manage.py runserver --noreload 8000
DEBUG 2020-03-07 13:50:28,401 selector_events 37100 Using selector: SelectSelector
Performing system checks...
System check identified no issues (0 silenced).
March 07, 2020 - 13:50:31
Django version 3.0.4, using settings 'backend.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Traceback (most recent call last):
File "D:/Projects/coursemanager/backend/manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "D:\Projects\coursemanager\backend\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "D:\Projects\coursemanager\backend\venv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\Projects\coursemanager\backend\venv\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\Projects\coursemanager\backend\venv\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "D:\Projects\coursemanager\backend\venv\lib\site-packages\django\core\management\base.py", line 369, in execute
output = self.handle(*args, **options)
File "D:\Projects\coursemanager\backend\venv\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "D:\Projects\coursemanager\backend\venv\lib\site-packages\django\core\management\commands\runserver.py", line 104, in run
self.inner_run(None, **options)
File "D:\Projects\coursemanager\backend\venv\lib\site-packages\django\core\management\commands\runserver.py", line 137, in inner_run
handler = self.get_handler(*args, **options)
File "D:\Projects\coursemanager\backend\venv\lib\site-packages\django\contrib\staticfiles\management\commands\runserver.py", line 27, in get_handler
handler = super().get_handler(*args, **options)
File "D:\Projects\coursemanager\backend\venv\lib\site-packages\django\core\management\commands\runserver.py", line 64, in get_handler
return get_internal_wsgi_application()
File "D:\Projects\coursemanager\backend\venv\lib\site-packages\django\core\servers\basehttp.py", line 45, in get_internal_wsgi_application
return import_string(app_path)
File "D:\Projects\coursemanager\backend\venv\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
module = import_module(module_path)
File "D:\Program Files\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "D:\Projects\coursemanager\backend\backend\wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "D:\Projects\coursemanager\backend\venv\lib\site-packages\django\core\wsgi.py", line 13, in get_wsgi_application
return WSGIHandler()
File "D:\Projects\coursemanager\backend\venv\lib\site-packages\django\core\handlers\wsgi.py", line 127, in __init__
self.load_middleware()
File "D:\Projects\coursemanager\backend\venv\lib\site-packages\django\core\handlers\base.py", line 37, in load_middleware
mw_instance = middleware(handler)
TypeError: __init__() takes 1 positional argument but 2 were given
Process finished with exit code 1
编辑:
在请求后在注释中添加了settings.py以将其包括在内。 settings.py:
import logging
import os
import sys
import logutils.colorize
import datetime
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'graphene_django',
'course',
'evaluation',
'training',
'rest_framework',
'rest_framework_jwt',
'import_export'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'graphql_jwt.middleware.JSONWebTokenMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
]
ROOT_URLCONF = 'backend.urls'
CORS_ORIGIN_WHITELIST = (
'https://localhost:3000',
'https://127.0.0.1:3000',
'http://localhost:3000',
'http://127.0.0.1:3000'
)
CORS_ORIGIN_ALLOW_ALL = True
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'backend.wsgi.application'
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
LANGUAGE_CODE = 'nl-NL'
TIME_ZONE = 'Europe/Amsterdam'
USE_I18N = True
USE_L10N = True
USE_TZ = True
DATE_FORMAT = "d-m-Y"
GRAPHENE = {
'SCHEMA': 'shared.schema.schema',
'MIDDLEWARE': [
'graphql_jwt.middleware.JSONWebTokenMiddleware',
],
}
GRAPHQL_JWT = {
'JWT_EXPIRATION_DELTA': datetime.timedelta(minutes=5),
'JWT_VERIFY_EXPIRATION': True,
'JWT_PAYLOAD_HANDLER': 'shared.schema.custom_jwt_payload'
}
AUTHENTICATION_BACKENDS = [
'graphql_jwt.backends.JSONWebTokenBackend',
'django.contrib.auth.backends.ModelBackend',
]
STATIC_ROOT = os.path.join(BASE_DIR, '../staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, '../static'),
)
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
答案 0 :(得分:0)
对于django 3.0和django-graphql-jwt 0.3.0,您的Django MIDDLWARE设置中不得包含graphql_jwt.middleware.JSONWebTokenMiddleware
。
仅在GRAPHENE设置下添加MIDDLEWARE部分。
从MIDDLWARE设置中删除graphql_jwt.middleware.JSONWebTokenMiddleware
应该可以解决此问题。
在此处查看django-graphql-jwt安装文档:https://pypi.org/project/django-graphql-jwt/0.3.0/