Opened 7 years ago

Closed 7 years ago

#29034 closed Bug (worksforme)

App Configs do not correctly handle static files

Reported by: nanomebia Owned by: nobody
Component: contrib.staticfiles Version: 2.0
Severity: Normal Keywords: staticfiles appconfigs
Cc: Florian Apolloner Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When following along with the djagno Polls tutorial I noticed the following behavior:

In tutorial 6 we learn about static files, and about how to correctly include them in our polls app. Following along with the tutorial exactly however leads us to a situation where the static files are not correctly included in the application and therefore our style.css does not get imported to our application.

The issue lies in tutorial 2 - where we first included our polls app in settings.py via INSTALLED_APPS:

INSTALLED_APPS = [
    'polls.apps.PollsConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

Using this method, static files do not get correctly imported to the app for inclusion in templates/etc

To fix this in the polls application, modifying INSTALLED_APPS as below produces the expected behavior (static files get included and can be accessed via templates.

INSTALLED_APPS = [
    'polls',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

According to apollo13 this seems to be a bug with handling of static files with app configs.

A quick fix for the tutorials may be changing the include text to just be "polls" vs "polls.apps.PollsConfig" however this may not be the desired syntax for app config includes.

Change History (1)

comment:1 by Tim Graham, 7 years ago

Resolution: worksforme
Status: newclosed

I can't reproduce a problem and if there were a bug, I think we'd have heard about it before now. You can seek help on our support channels. If you provide an upload of your project, someone may be able to debug it and find where you went wrong.

Note: See TracTickets for help on using tickets.
Back to Top