Я пытаюсь развернуть свой django -rest-framework api на PythonAnywhere.com, но продолжаю получать django .contrib.session не может быть найден.
** Я прочитал документацию по PythonAnywher.com и выполнил следующие шаги: (https://help.pythonanywhere.com/pages/DeployExistingDjangoProject) (https://help.pythonanywhere.com/pages/DebuggingImportError)
- смог запустить wsgi.py сам файл
- смог запустить import myproject.settings без ошибок
- смог запустить python /path/to/myapp/settings.py без ошибок
- Не смог понять, что они имели в виду под «слежкой». Все пакеты импортированы в virutalenv через pipfile
- удалось проверить Проверить правильность версий virtualenv Python **
Settings.py
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = 'its a secret'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'corsheaders',
'rest_framework',
'menus',
'login',
]
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'chefsBackEnd.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
'django.template.context_processors.media',
],
},
},
]
WSGI_APPLICATION = 'chefsBackEnd.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# DATABASES = {}
# DATABASES['default'] = dj_database_url.config(conn_max_age=600)
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
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 = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
SITE_ID = 1
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.AllowAny',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
# 'rest_framework.authentication.TokenAuthentication',
# 'rest_framework_simplejwt.authentication.JWTAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
)
}
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_WHITELIST = [
# 'http://localhost:3000',
# 'http://localhost:5000',
'https://chefs-table-mock-site.herokuapp.com',
'https://git.heroku.com/phlog-api.git'
]
CORS_ALLOW_METHODS = [
'DELETE',
'GET',
'OPTIONS',
'PATCH',
'POST',
'PUT',
]
JWT_AUTH = {
'JWT_RESPONSE_PAYLOAD_HANDLER': 'chefsBackEnd.utils.resp_handler',
'JWT_ALGORITHM': 'HS256',
'JWT_VERIFY': True,
}
CSRF_COOKIE_NAME = "csrftoken"
> Traceback (most recent call last): File
> "/home/jgartsu12/.virtualenvs/chefsBackEnd-virtualenv/lib/python3.8/site-packages/django/apps/config.py",
> line 118, in create
> cls = getattr(mod, cls_name)
> **AttributeError: module 'django.contrib' has no attribute 'sessions'** During handling of the above exception, another exception
> occurred: Traceback (most recent call last): File "manage.py", line
> 21, in <module>
> main() File "manage.py", line 17, in main
> execute_from_command_line(sys.argv) File "/home/jgartsu12/.virtualenvs/chefsBackEnd-virtualenv/lib/python3.8/site-packages/django/core/management/__init__.py",
> line 401, in execute_f rom_command_line
> utility.execute() File "/home/jgartsu12/.virtualenvs/chefsBackEnd-virtualenv/lib/python3.8/site-packages/django/core/management/__init__.py",
> line 377, in execute
> django.setup() File "/home/jgartsu12/.virtualenvs/chefsBackEnd-virtualenv/lib/python3.8/site-packages/django/__init__.py",
> line 24, in setup
> apps.populate(settings.INSTALLED_APPS) File "/home/jgartsu12/.virtualenvs/chefsBackEnd-virtualenv/lib/python3.8/site-packages/django/apps/registry.py",
> line 91, in populate
> app_config = AppConfig.create(entry) File "/home/jgartsu12/.virtualenvs/chefsBackEnd-virtualenv/lib/python3.8/site-packages/django/apps/config.py",
> line 136, in create
> import_module(entry) File "/home/jgartsu12/.virtualenvs/chefsBackEnd-virtualenv/lib/python3.8/importlib/__init__.py",
> line 127, in import_module
> return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File
> "<frozen importlib._bootstrap>", line 991, in _find_and_load File
> "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
> **ModuleNotFoundError: No module named 'django.contrib.sessions'**
На основании этого ImportError: Нет модуля с именем 'django .contrib.sessions' , они смогли изменить версию django на ту, которую я должен запустить, но я продолжаю сталкиваться с та же проблема.
Это должно быть проблема с данной версией Django (1.10.5), поскольку обновление до 1.10.8, похоже, решило ее. - { ссылка }
Кроме того, это из журналов ошибок на PythonAnywhere.com:
> 2020-07-08 19:54:28,687: Not Found: /favicon.ico 2020-07-08
> 21:27:50,215: Not Found: /static/admin/css/fonts.css 2020-07-08
> 21:31:05,154: Not Found: /static/admin/css/base.css 2020-07-08
> 21:31:05,157: Not Found: /static/admin/css/login.css 2020-07-08
> 21:31:05,194: Not Found: /static/admin/css/responsive.css 2020-07-08
> 21:31:15,815: Not Found: /static/admin/css/base.css 2020-07-08
> 21:31:15,819: Not Found: /static/admin/css/login.css 2020-07-08
> 21:31:15,825: Not Found: /static/admin/css/responsive.css 2020-07-08
> 21:31:26,680: Not Found: /static/admin/css/base.css 2020-07-08
> 21:31:26,685: Not Found: /static/admin/css/login.css 2020-07-08
> 21:31:26,689: Not Found: /static/admin/css/responsive.css 2020-07-08
> 21:31:36,012: Not Found: /api 2020-07-08 21:34:15,458: Not Found:
> /static/admin/css/fonts.css 2020-07-08 21:37:24,180: Not Found:
> /static/admin/css/fonts.css 2020-07-10 22:25:10,104: Error running
> WSGI application 2020-07-10 22:25:10,124: ModuleNotFoundError: No
> module named 'django.contrib.sessions' 2020-07-10 22:25:10,124: File
> "/var/www/jgartsu12_pythonanywhere_com_wsgi.py", line 16, in <module>
> 2020-07-10 22:25:10,124: application = get_wsgi_application()
> 2020-07-10 22:25:10,124: 2020-07-10 22:25:10,124: File
> "/home/jgartsu12/.virtualenvs/chefsBackEnd-virtualenv/lib/python3.8/site-packages/django/core/wsgi.py",
> line 12, in get_wsgi_application 2020-07-10 22:25:10,125:
> django.setup(set_prefix=False) 2020-07-10 22:25:10,125: 2020-07-10
> 22:25:10,125: File
> "/home/jgartsu12/.virtualenvs/chefsBackEnd-virtualenv/lib/python3.8/site-packages/django/__init__.py",
> line 24, in setup 2020-07-10 22:25:10,125:
> apps.populate(settings.INSTALLED_APPS) 2020-07-10 22:25:10,125:
> 2020-07-10 22:25:10,125: File
> "/home/jgartsu12/.virtualenvs/chefsBackEnd-virtualenv/lib/python3.8/site-packages/django/apps/registry.py",
> line 91, in populate 2020-07-10 22:25:10,125: app_config =
> AppConfig.create(entry) 2020-07-10 22:25:10,125: 2020-07-10
> 22:25:10,126: File
> "/home/jgartsu12/.virtualenvs/chefsBackEnd-virtualenv/lib/python3.8/site-packages/django/apps/config.py",
> line 136, in create 2020-07-10 22:25:10,126: import_module(entry)