Opened 15 years ago

Closed 14 years ago

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

Download all attachments as: .zip

Change History (21)

by Viktor, 15 years ago

Attachment: static_media.diff added

comment:1 by Carl Meyer, 15 years ago

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

Cc: Jannis Leidel added

comment:3 by Luke Plant, 15 years ago

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 by Eric Holscher, 15 years ago

Triage Stage: UnreviewedAccepted

comment:5 by Jannis Leidel, 15 years ago

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.

by Luke Plant, 15 years ago

Attachment: 12323.1.diff added

Alternative patch - introduce USER_MEDIA_ROOT and USER_MEDIA_URL

comment:7 by Jannis Leidel, 15 years ago

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

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

by Jannis Leidel, 14 years ago

Attachment: 12323.2.diff added

Latest patch from Github.

comment:9 by Jannis Leidel, 14 years ago

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

by Jannis Leidel, 14 years ago

Attachment: 12323.3.diff added

Caching the file finders.

comment:10 by Jannis Leidel, 14 years ago

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

by Jannis Leidel, 14 years ago

Attachment: 12323.4.diff added

logging adoption and other smaller things

by Jannis Leidel, 14 years ago

Attachment: 12323.5.diff added

removed logging again and fixed a few other things

by Jannis Leidel, 14 years ago

Attachment: 12323.6.diff added

Refactored utilities and management command.

by Jannis Leidel, 14 years ago

Attachment: 12323.7.diff added

initial docs

by Jannis Leidel, 14 years ago

Attachment: 12323.8.diff added

more fixed. removed optionappcommand class.

comment:11 by Jannis Leidel, 14 years ago

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 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

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