Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#21724 closed Uncategorized (worksforme)

no default static subdirectory search in project package

Reported by: anonymous Owned by: nobody
Component: Documentation Version: 1.6
Severity: Normal Keywords: settings, templates, staticfiles
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no



In Setting STATICFILES_FINDERS (and Tutorial 6):

The default will find files stored in the STATICFILES_DIRS setting ... and in a static subdirectory of each app ...

I found out that this does not include the project's package. Working my way through the tutorials I expected dedicated apps (such as polls) and the projects package (such as mysite) to behave no different. That is Django searches for static files in polls/static/ and in mysite/static/.

That is not the case, though, and is highly unexpected for two reasons:

  • Writing code as an app is optional (at least that's what remained after reading the tutorial). Why exclude the mandatory (project) from the rule?
  • General behaviour goes in the app folder, custom settings go into the project folder. Templates and static files like CSS fall into the later category. Why exclude the intended location from the default search? Why must I change the defaults to support the major case?

On the other hand if there is a deeper meaning in the directory structure you failed to explain it throughout the tutorial.

Change History (2)

comment:1 Changed 4 years ago by Jannis Leidel

Resolution: worksforme
Status: newclosed

This is intended behavior. The startproject management command as shown in the tutorial only exists for the purpose of getting started with a simple directory layout. But since Django needs to be flexible enough to accommodate more complex project set ups, it doesn't make sense to force a certain "project" layout for optional features like static files (or translation catalogs, templates and fixtures). In other words, we leave it to the users to define where exactly the "project" static files are supposed to be. We provide a helper variable in recent project setting templates called BASE_DIR for use with Python's os.path.join in settings like STATICFILES_DIRS, TEMPLATE_DIRS, LOCALE_PATHS and FIXTURE_DIRS. As to whether we should try to explain all this in the tutorial I think I'd rather consider this more an "advanced" technique and hence not needed to be discussed in the tutorial.

comment:2 Changed 4 years ago by Cody Scott

You can add your project directory as an app, and in 1.7 you won't need a file.

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