Simple Django app deployed on Azure App Service keeps showing application error
enter image description here It keeps showing error after the app has been succesfully deployed on the Azure App Service, has anyone experienced something similar to this?
I have tried ssh into it to confirm my files are intact and they are all right, was expecting the default index page I built for the application
I tried deploying a Django app to Azure App Service.
First, install the django using pip
pip install django
Create your Django project:
django-admin startproject yourprojectname
cd yourprojectname
Create a virtual environment for the app
py -m venv .venv
.venv\scripts\activate
Here, you need to create a requirements.txt file to list all the dependencies required for the project.
pip freeze > requirements.txt
Install dependencies:
pip install -r requirements.txt
Run the app :
python manage.py runserver
Ensure your wsgi.py correctly sets the DJANGO_SETTINGS_MODULE to 'yourproject.settings' and also ensure your project structure is consistent. Make sure your packages are up to date.
manage.py
import os
import sys
def main():
settings_module = 'project.production' if 'WEBSITE_HOSTNAME' in os.environ else 'project.settings'
os.environ.setdefault('DJANGO_SETTINGS_MODULE', settings_module)
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
This is the content of my settings.py file
import os
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = 'secretkey'
DEBUG = True
ALLOWED_HOSTS = [
INSTALLED_APPS = [
"whitenoise.runserver_nostatic",
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'hello_azure',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
# Add whitenoise middleware after the security middleware
'whitenoise.middleware.WhiteNoiseMiddleware',
'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 = 'project.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 = 'project.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
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_TZ = True
STATICFILES_DIRS = (str(BASE_DIR.joinpath('static')),)
STATIC_URL = 'static/'
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
Local output :


I deployed the Django app to Azure App Service using the VS Code Azure Extension.
Here are the steps:
Select your Azure subscription.
Then, select your created web app.
Right-click on the web app; you can see the "Deploy to Web App" option.


The deployment to azure app service was successful.
To view the website in the browser, right-click on your Azure app service and select Browse Site.

To check the deployed files in azure
1.Open you're Azure app service.
Search for Advanced Tools and click on it.
Afterward, click on Go.


4.Inside the wwwroot folder of the site, you can find your deployed files.

Here's the output:

I have been able to sort it out, for my start gunicorn command I was writing gunicorn --bind=0.0.0.0 --timeout 600 --chdir /mysite mysite.wsgi instead of gunicorn --bind=0.0.0.0 --timeout 600 --chdir ./mysite mysite.wsgi
One '.' can change everything lol, thanks so much everyone for the help