Opened 7 years ago

Closed 6 years ago

Last modified 5 years ago

#12323 closed (fixed)

Ease handling of static files (e.g. included in apps)

Reported by: Viktor Owned by: Jannis Leidel
Component: Core (Other) Version:
Severity: Keywords: settings, media_url, media_root, static_url, static_root
Cc: Jannis Leidel Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Separating user uploaded media from site-specific media seems to be meaningful. Thus a separate STATIC_URL, STATIC_ROOT setting would be helpful.
A description of this approach is given by Peter Baumgartner.

The attached patch adds STATIC_URL and STATIC_ROOT to global_settings defaulting them to MEDIA_URL and MEDIA_ROOT, respectively.
The patch works with 1.1 and trunk too.

Attachments (9)

static_media.diff (2.5 KB) - added by Viktor 7 years ago.
12323.1.diff (13.6 KB) - added by Luke Plant 6 years ago.
Alternative patch - introduce USER_MEDIA_ROOT and USER_MEDIA_URL
12323.2.diff (61.5 KB) - added by Jannis Leidel 6 years ago.
Latest patch from Github.
12323.3.diff (61.7 KB) - added by Jannis Leidel 6 years ago.
Caching the file finders.
12323.4.diff (60.7 KB) - added by Jannis Leidel 6 years ago.
logging adoption and other smaller things
12323.5.diff (60.1 KB) - added by Jannis Leidel 6 years ago.
removed logging again and fixed a few other things
12323.6.diff (60.6 KB) - added by Jannis Leidel 6 years ago.
Refactored utilities and management command.
12323.7.diff (70.6 KB) - added by Jannis Leidel 6 years ago.
initial docs
12323.8.diff (68.3 KB) - added by Jannis Leidel 6 years ago.
more fixed. removed optionappcommand class.

Download all attachments as: .zip

Change History (21)

Changed 7 years ago by Viktor

Attachment: static_media.diff added

comment:1 Changed 7 years ago by Carl Meyer

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

I think the primary gain here would be if the form Media could be converted to use the new STATIC_ROOT setting rather than MEDIA_ROOT; currently form media in reusable apps using relative URL paths is a nasty sticking point if you are trying to separate user-uploaded media from static assets.

Also, the static file serving documentation page currently demonstrates the creation of a custom setting, STATIC_DOC_ROOT; that could perhaps be changed to STATIC_ROOT if this goes through.

comment:2 Changed 7 years ago by Jannis Leidel

Cc: Jannis Leidel added

comment:3 Changed 7 years ago by Luke Plant

I agree that this is a problem, and one that I'd like to see a solution to.

Your patch isn't actually backwards compatible, AFAICS, because setting STATIC_ROOT = MEDIA_ROOT in global_settings.py does not make the value of MEDIA_ROOT the default value of STATIC_ROOT - it makes '' the default value of STATIC_ROOT. It might be possible to find a way to do this using lazy(), or alternatively using a utility function get_static_root() that returns MEDIA_ROOT if STATIC_ROOT is not defined.

comment:4 Changed 7 years ago by Eric Holscher

Triage Stage: UnreviewedAccepted

comment:5 Changed 7 years ago by Jannis Leidel

Version: 1.1

As a matter of reference I'd like to point to my app django-staticfiles that was extracted from Pinax and strives to solve this exact use case described here. Incidentally it also uses STATIC_ROOT and STATIC_URL settings to complement MEDIA_ROOT and MEDIA_URL.

Changed 6 years ago by Luke Plant

Attachment: 12323.1.diff added

Alternative patch - introduce USER_MEDIA_ROOT and USER_MEDIA_URL

comment:6 Changed 6 years ago by Luke Plant

comment:7 Changed 6 years ago by Jannis Leidel

I've also started to implement a slightly different approach that was discussed at the DjagnoCon Europe sprint at http://github.com/jezdez/django/tree/staticfiles

comment:8 Changed 6 years ago by Jannis Leidel

milestone: 1.3
Owner: changed from nobody to Jannis Leidel
Status: newassigned

Changed 6 years ago by Jannis Leidel

Attachment: 12323.2.diff added

Latest patch from Github.

comment:9 Changed 6 years ago by Jannis Leidel

I'm waiting with the modifications of the logging code in the patch till the logging code lands in trunk.

Changed 6 years ago by Jannis Leidel

Attachment: 12323.3.diff added

Caching the file finders.

comment:10 Changed 6 years ago by Jannis Leidel

Summary: add support for STATIC_URL and STATIC_ROOTEase handling of static files (e.g. included in apps)

Changed 6 years ago by Jannis Leidel

Attachment: 12323.4.diff added

logging adoption and other smaller things

Changed 6 years ago by Jannis Leidel

Attachment: 12323.5.diff added

removed logging again and fixed a few other things

Changed 6 years ago by Jannis Leidel

Attachment: 12323.6.diff added

Refactored utilities and management command.

Changed 6 years ago by Jannis Leidel

Attachment: 12323.7.diff added

initial docs

Changed 6 years ago by Jannis Leidel

Attachment: 12323.8.diff added

more fixed. removed optionappcommand class.

comment:11 Changed 6 years ago by Jannis Leidel

Resolution: fixed
Status: assignedclosed

(In [14293]) Fixed #12323 and #11582 -- Extended the ability to handle static files. Thanks to all for helping with the original app, the patch, documentation and general support.

comment:12 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

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