Hello Friends, sadly my bootcamp did not go over in-depth deployment lessons. My Api is running into the following errors and I am not sure how to troubleshoot. I followed the documentation to manually deploy. I am pretty sure I am not accurately configuring the WSGI files in my code's repor, and not setting the right path. From my logs i am receiving the following error:
2022-10-25 19:59:21,669: ***************************************************
202`enter code here`2-10-25 20:02:14,652: Error running WSGI application
2022-10-25 20:02:14,657: ModuleNotFoundError: No module named 'thoughts'
2022-10-25 20:02:14,657: File "/var/www/cschadeck_pythonanywhere_com_wsgi.py", line 16, in <module>
2022-10-25 20:02:14,658: application = get_wsgi_application()
2022-10-25 20:02:14,658:
2022-10-25 20:02:14,658: File "/home/CSchadeck/.virtualenvs/Thoughts-virtualenv/lib/python3.10/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2022-10-25 20:02:14,658: django.setup(set_prefix=False)
2022-10-25 20:02:14,658:
2022-10-25 20:02:14,658: File "/home/CSchadeck/.virtualenvs/Thoughts-virtualenv/lib/python3.10/site-packages/django/__init__.py", line 19, in setup
2022-10-25 20:02:14,658: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2022-10-25 20:02:14,659:
2022-10-25 20:02:14,659: File "/home/CSchadeck/.virtualenvs/Thoughts-virtualenv/lib/python3.10/site-packages/django/conf/__init__.py", line 92, in __getattr__
2022-10-25 20:02:14,659: self._setup(name)
2022-10-25 20:02:14,659:
2022-10-25 20:02:14,659: File "/home/CSchadeck/.virtualenvs/Thoughts-virtualenv/lib/python3.10/site-packages/django/conf/__init__.py", line 79, in _setup
2022-10-25 20:02:14,659: self._wrapped = Settings(settings_module)
2022-10-25 20:02:14,659:
2022-10-25 20:02:14,660: File "/home/CSchadeck/.virtualenvs/Thoughts-virtualenv/lib/python3.10/site-packages/django/conf/__init__.py", line 190, in __init__
2022-10-25 20:02:14,660: mod = importlib.import_module(self.SETTINGS_MODULE)
My current configuration on pythonanyware;s deployment is as follows
# +++++++++++ DJANGO +++++++++++
# To use your own Django app use code like this:
import os
import sys
path = '/home/CSchadeck/Thoughts-and-Feelings-API/thoughts/settings.py'
if path not in sys.path:
sys.path.insert(0, path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'thoughts.settings'
## Uncomment the lines below depending on your Django version
###### then, for Django >=1.5:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
###### or, for older Django <=1.4
#import django.core.handlers.wsgi
#application = django.core.handlers.wsgi.WSGIHandler()
In my code my manage.py file is in my code's main directory. Here is that code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
All my code for my API is in a thoughts folder which is also in the main directory.
wsgi.py.py code is:
"""
WSGI config for thoughts project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "thoughts.settings")
application = get_wsgi_application()
If it helps my settings.py code is:
"
""
Django settings for thoughts project.
Generated by 'django-admin startproject' using Django 4.1.2.
For more information on this file, see
https://docs.djangoproject.com/en/4.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-bxb4*=78)7-xt7pn*0!m%7nik75@wd#cujtj6$&!jopj=z47a#"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
"corsheaders",
'rest_framework',
'thoughts',
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]
MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOW_METHODS = [
'DELETE',
'GET',
'OPTIONS',
'PATCH',
'POST',
'PUT',
]
CORS_ALLOW_HEADERS = [
'accept',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
]
CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOW_CREDENTIALS: True
ROOT_URLCONF = "thoughts.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",
],
},
},
]
WSGI_APPLICATION = "thoughts.wsgi.application"
# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}
# Password validation
# https://docs.djangoproject.com/en/4.1/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", },
]
# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = "static/"
# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
Thank you in advance for your help and patience for a new developer.