skip to Main Content

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

  • Here are the logs:
    2024-03-02T16:09:02.869Z INFO – Initiating warmup request to container testlive_0_f3462e59 for site testlive
    2024-03-02T16:09:22.131Z ERROR – Container testlive_0_f3462e59 for site testlive has exited, failing site start
    2024-03-02T16:09:22.144Z ERROR – Container testlive_0_f3462e59 didn’t respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
    2024-03-02T16:09:22.184Z INFO – Stopping site testlive because it failed during startup.

2

Answers


  1. Chosen as BEST ANSWER

    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


  2. 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
    .venvscriptsactivate
    

    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 :

    enter image description here

    enter image description here

    I deployed the Django app to Azure App Service using the VS Code Azure Extension.

    Here are the steps:

    1. Select your Azure subscription.

    2. Then, select your created web app.

    3. Right-click on the web app; you can see the "Deploy to Web App" option.

    enter image description here

    enter image description here

    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.

    enter image description here

    To check the deployed files in azure

    1.Open you’re Azure app service.

    1. Search for Advanced Tools and click on it.

    2. Afterward, click on Go.

    enter image description here

    enter image description here

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

    enter image description here

    Here’s the output:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search