Recommand · May 29, 2021 0

django web app deployment on windows 10 using apache server(WAMP) not displaying CSS for admin site

On Windows 10 django app when run using development server by using command python runserver shows admin login page and admin site correctly. but if same django app at same path when served using apache is not displaying css correctly for admin login and other admin site pages.

I have tried to follow steps at but some configuration/setting is missed/incorrect resulting in css not applied to admin login page and admin site.
my development and deployment is on same windows 10 computer with WAMP server
I have installed mod_wsgi and following are relevent section from
import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.

BASE_DIR = Path(__file__).resolve().parent.parent

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'secrete key is listed here'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False


MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'), ]

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')


# Application definition




ROOT_URLCONF = 'hellodjangodeployapache_project.urls'

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [

WSGI_APPLICATION = 'hellodjangodeployapache_project.wsgi.application'

# Database

    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',

# Password validation

        '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



USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)

STATIC_URL = '/static/'

# Default primary key field type

    enter code here

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

my projects looks like as below

from django.contrib import admin
from django.urls import include, path
from . import views
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
                  path('polls/', include('polls.urls')),
                  path('', views.home, name='home'),

              ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) is as below

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hellodjangodeployapache_project.settings')

application = get_wsgi_application()

django project directory structure is as shown in picture below

project directory structure

following lines are added to httpd.conf of apache server

# LoadFile "d:/pythoninstallation/python39.dll"
LoadModule wsgi_module "c:/users/admin/envs/hellodjangodeployapacheenv/lib/site-packages/mod_wsgi/server/mod_wsgi.cp39-win_amd64.pyd"
WSGIPythonHome "c:/users/admin/envs/hellodjangodeployapacheenv"

WSGIPythonPath "D:/djangoprojects/hellodjangodeployapache/hellodjangodeployapache_project"

<Directory "D:/djangoprojects/hellodjangodeployapache/hellodjangodeployapache_project">
Require all granted

Alias /media/ "D:/djangoprojects/hellodjangodeployapache/hellodjangodeployapache_project/media/"

Alias /static/ "D:/djangoprojects/hellodjangodeployapache/hellodjangodeployapache_project/static/"

<Directory "D:/djangoprojects/hellodjangodeployapache/hellodjangodeployapache_project/static/">
Require all granted

<Directory "D:/djangoprojects/hellodjangodeployapache/hellodjangodeployapache_project/media/">
Require all granted

WSGIScriptAlias / "D:/djangoprojects/hellodjangodeployapache/hellodjangodeployapache_project/hellodjangodeployapache_project/"

<Directory "D:/djangoprojects/hellodjangodeployapache/hellodjangodeployapache_project/hellodjangodeployapache_project">
Require all granted

following is httpd-vhosts.conf file content

# Virtual Hosts
<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "${INSTALL_DIR}/www"
#  <Directory "${INSTALL_DIR}/www/">
#    Options +Indexes +Includes +FollowSymLinks +MultiViews
#    AllowOverride All
#    Require local
#  </Directory>

wamp server is installed at C:\wamp64 and content of C:\wamp64\www is empty.
virtual envirornment is created using virtualenvwrapper-win and its name is hellodjangodeployapacheEnv.

when django webpapp is run using python runserver and opened using it shows admin login page/admin site properly but it is served apache with above mentioned configuration settings http://localhost/admin shows admin login page and admin site without css.
what is change is needed in above mentioned settings/ configuration files so that admin login/ admin site shows normal CSS when served using apache server on windows 10.?