1

I am getting a similar error to this post, but it only happens when I go to the website I set up in IIS 2012R2.

I am following this tutorial to start a web app, and I used this video to set up Django with IIS. I successfully set up the Django using IIS, but I a missing the CSS on the admin page.

Note that the admin page displays the CSS items if I run the page using runserver command.

python manage.py runserver

But if I run it through http://127.0.0.1:8003/admin/ in IE (setup through IIS), I get the picture shown below. I tried this in Chrome, and it gave me same results.

Do I need configure my wfastcgi.py file to show CSS? In the video tutorial, the author talks about a static folder in IIS for JPEGS, Javascript...do I need to configure this?

enter image description here

I am using Django 1.8.4 and Python 3.4.

This is my current configuration:

settings.py

    # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '&y%=6k2y4z5_ut3z#&1l2lh3v12#zyxws)o&5^fj^ik^79pys('

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

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin', #admin site
    'django.contrib.auth', #authentication system
    'django.contrib.contenttypes', #framework for content types
    'django.contrib.sessions', #ssession framework
    'django.contrib.messages', #messaging framework
    'django.contrib.staticfiles', #framework for managing static files
    'polls',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'FirstSite.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 = 'FirstSite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'

urls.py

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),]

wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "FirstSite.settings")

application = get_wsgi_application()

manage.py

import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "FirstSite.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

2 Answers 2

2

You should set your STATICFILES_DIRS settings in settings.py, to map to your static folder, where CSS, JS and images are stored.

STATIC_URL = 'http://www.example.com/static/'

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

Also if you run 'manage.py collectstatic' you should define

STATIC_ROOT = "/path/to/static/destination/folder/"

This is the best way to serve static files.

Reference for STATIC settings: Django Documentation

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your solution, the CSS is now showing. I did not end up needing STATICFILES_DIRS, I just mapped the static files to STATIC_ROOT after the 'manage.py collecstatic. Do you think I need to use the STATICFILES_DIRS?
1

I was able to find an answer with the help of a colleague.

The answer is highlighted here: Link

If you follow the above solution, please keep in mind the following (which is what the above person mentioned):

  • The Static folder where you keep all the CSS, jpegs, etc files is not the same as the static folder they are referring to in the solution
  • Make sure you run the command collectstatic to compile all the static files from the STATIC_URL folder to the STATIC_ROOT folder
  • When you run the collectstatic it will compile the Admin static files as well

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.