No CSS in Admin panel in Azure App Service hosted Django APP

Issue

I cant figure out how to make Azure App Service use css for admin panel.
In settings.py I included these:

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

   
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

But somehow css is still not working for the admin panel.
How can I fix this? As far as I know Oryx which works under Azure App Service should automatically run

python manage.py collectstatic

Any ideas?

EDIT:
Installed apps

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken',
    'licenses_api',
]

Solution

There are something to check might help:

  1. Click F12 on your Admin page to check if it is the 404 Not Found error.

  2. Check the static files exist in your azure web app or not. You could see it in https://{your-web-app}.scm.azurewebsites.net/wwwroot/ site.

  3. Check if your file structure match with the settings.py. Any spell error would make the static file not found.

  4. If your file exists well, you should check if you use them correctly in your code like this answer. Here is how he use:

     from django.conf.urls.static import static
    
     urlpatterns = [
             path('myapp/', include('myapp.urls')),
             path('admin/', admin.site.urls),
         ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    

Answered By – Doris Lv

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published