Opened 11 years ago

Closed 10 years ago

Last modified 9 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: no UI/UX: no

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

Download all attachments as: .zip

Change History (21)

Changed 11 years ago by Viktor

Attachment: static_media.diff added

comment:1 Changed 11 years ago by Carl Meyer

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 11 years ago by Jannis Leidel

Cc: Jannis Leidel added

comment:3 Changed 11 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 11 years ago by Eric Holscher

Triage Stage: UnreviewedAccepted

comment:5 Changed 11 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 11 years ago by Luke Plant

Attachment: 12323.1.diff added

Alternative patch - introduce USER_MEDIA_ROOT and USER_MEDIA_URL

comment:6 Changed 11 years ago by Luke Plant

comment:7 Changed 11 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 10 years ago by Jannis Leidel

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

Changed 10 years ago by Jannis Leidel

Attachment: 12323.2.diff added

Latest patch from Github.

comment:9 Changed 10 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 10 years ago by Jannis Leidel

Attachment: 12323.3.diff added

Caching the file finders.

comment:10 Changed 10 years ago by Jannis Leidel

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

Changed 10 years ago by Jannis Leidel

Attachment: 12323.4.diff added

logging adoption and other smaller things

Changed 10 years ago by Jannis Leidel

Attachment: 12323.5.diff added

removed logging again and fixed a few other things

Changed 10 years ago by Jannis Leidel

Attachment: 12323.6.diff added

Refactored utilities and management command.

Changed 10 years ago by Jannis Leidel

Attachment: 12323.7.diff added

initial docs

Changed 10 years ago by Jannis Leidel

Attachment: 12323.8.diff added

more fixed. removed optionappcommand class.

comment:11 Changed 10 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 9 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

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