azuredeploymentazure-web-app-servicewebdeployazure-deployment

Azure Web App - Error deploying python (django) application


I'm trying to deploy using the github actions from this repository: https://github.com/ViniciusDevelopment/test-deployment

which is basically a modification of the standard project made available by Microsoft for testing and learning(link azure):

git clone https://github.com/Azure-Samples/msdocs-python-django-webapp-quickstart

The base project provided by the corporation performed well. However, when adding another app and executing the commit, several errors occur, from gateway to error 500

the log stream didn't give me any relevant information

enter image description here

enter image description here

enter image description here enter image description here


Solution

  • I tried your code, made some changes, and was able to deploy it to Azure without any issues.

    Ensure your wsgi.py correctly sets the DJANGO_SETTINGS_MODULE to 'Quickproject.settings' and ensure your project structure is consistent. Make sure your packages are up to date.

    Settings.py:

    import os
    from pathlib import Path
    BASE_DIR = Path(__file__).resolve().parent.parent
    SECRET_KEY = '1234567890'
    DEBUG = True
    APPEND_SLASH = False
    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',
        'AppPlanEx',
    ]
    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 = 'quickstartproject.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 = 'quickstartproject.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
    
    STATIC_URL = '/static/'
    STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
    DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
    
    DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
    
    

    quickstartproject/urls.py:

    from  django.contrib  import  admin
    from  django.urls  import  include, path
    from  quickstartproject  import  settings
    from  django.conf.urls.static  import  static
    urlpatterns  = [
    path('', include('hello_azure.urls')),
    path('appplanex/', include('AppPlanEx.urls')),
    path('ttt/', include('hello_azure.urls')),
    path('admin/', admin.site.urls),
    ]  
    if  settings.DEBUG:
    urlpatterns  +=  static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    

    hello_azure/urls.py:

    from  django.urls  import  path
    from . import  views
    from  quickstartproject  import  settings
    from  django.conf.urls.static  import  static
    urlpatterns  = [
    path('', views.index, name='index'),
    path('hello/', views.hello, name='hello'),
    ]
    if  settings.DEBUG:
    urlpatterns  +=  static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    

    hello_azure/views.py:

    from  django.shortcuts  import  render, redirect
    from  django.http  import  HttpResponse
    from  django.views.decorators.csrf  import  csrf_exempt 
    def  index(request):
    print('Request for index page received')
    return  render(request, 'hello_azure/index.html') 
    @csrf_exempt
    def  hello(request):
    if  request.method ==  'POST':
    name  =  request.POST.get('name')
    if  name  is  None  or  name  ==  '':
    print("Request for hello page received with no name -- redirecting")
    return  redirect('index')
    else:
    print("Request for hello page received with name=%s"  %  name)
    context  = {'name': name }
    return  render(request, 'hello_azure/hello.html', context)
    else:
    return  redirect('index')
    

    AppPlanEx/urls.py:

    from  django.urls  import  path
    from . import  views
    from  quickstartproject  import  settings
    from  django.conf.urls.static  import  static
    urlpatterns  = [
    path('', views.Home, name="Home"),
    path('appplanex/', views.Home, name="appplanex"),
    ]
    if  settings.DEBUG:
    urlpatterns  +=  static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    

    Here's the local Output:

    enter image description here

    enter image description here

    After making the above changes to your code, I was able to deploy the app to Azure App Service using GitHub Actions successfully.

    Here's the output:

    enter image description here

    enter image description here