Code

Opened 5 years ago

Closed 4 years ago

Last modified 3 years ago

#12323 closed (fixed)

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

Reported by: nagyv Owned by: jezdez
Component: Core (Other) Version:
Severity: Keywords: settings, media_url, media_root, static_url, static_root
Cc: jezdez 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 nagyv 5 years ago.
12323.1.diff (13.6 KB) - added by lukeplant 4 years ago.
Alternative patch - introduce USER_MEDIA_ROOT and USER_MEDIA_URL
12323.2.diff (61.5 KB) - added by jezdez 4 years ago.
Latest patch from Github.
12323.3.diff (61.7 KB) - added by jezdez 4 years ago.
Caching the file finders.
12323.4.diff (60.7 KB) - added by jezdez 4 years ago.
logging adoption and other smaller things
12323.5.diff (60.1 KB) - added by jezdez 4 years ago.
removed logging again and fixed a few other things
12323.6.diff (60.6 KB) - added by jezdez 4 years ago.
Refactored utilities and management command.
12323.7.diff (70.6 KB) - added by jezdez 4 years ago.
initial docs
12323.8.diff (68.3 KB) - added by jezdez 4 years ago.
more fixed. removed optionappcommand class.

Download all attachments as: .zip

Change History (21)

Changed 5 years ago by nagyv

comment:1 Changed 5 years ago by carljm

  • 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 5 years ago by jezdez

  • Cc jezdez added

comment:3 Changed 5 years ago by lukeplant

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 4 years ago by ericholscher

  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 4 years ago by jezdez

  • Version 1.1 deleted

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 4 years ago by lukeplant

Alternative patch - introduce USER_MEDIA_ROOT and USER_MEDIA_URL

comment:6 Changed 4 years ago by lukeplant

comment:7 Changed 4 years ago by jezdez

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 4 years ago by jezdez

  • milestone set to 1.3
  • Owner changed from nobody to jezdez
  • Status changed from new to assigned

Changed 4 years ago by jezdez

Latest patch from Github.

comment:9 Changed 4 years ago by jezdez

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

Changed 4 years ago by jezdez

Caching the file finders.

comment:10 Changed 4 years ago by jezdez

  • Summary changed from add support for STATIC_URL and STATIC_ROOT to Ease handling of static files (e.g. included in apps)

Changed 4 years ago by jezdez

logging adoption and other smaller things

Changed 4 years ago by jezdez

removed logging again and fixed a few other things

Changed 4 years ago by jezdez

Refactored utilities and management command.

Changed 4 years ago by jezdez

initial docs

Changed 4 years ago by jezdez

more fixed. removed optionappcommand class.

comment:11 Changed 4 years ago by jezdez

  • Resolution set to fixed
  • Status changed from assigned to closed

(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 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.