#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)
Change History (21)
by , 16 years ago
| Attachment: | static_media.diff added |
|---|
comment:1 by , 16 years ago
comment:2 by , 16 years ago
| Cc: | added |
|---|
comment:3 by , 16 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 , 16 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:5 by , 16 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 , 15 years ago
| Attachment: | 12323.1.diff added |
|---|
Alternative patch - introduce USER_MEDIA_ROOT and USER_MEDIA_URL
comment:6 by , 15 years ago
See http://groups.google.com/group/django-developers/browse_thread/thread/b333c14f40acd22a for discussion.
See lp_ticket-12323 branch of http://bitbucket.org/spookylukey/django-trunk-lukeplant/ for my implementation of this patch.
comment:7 by , 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 , 15 years ago
| milestone: | → 1.3 |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
comment:9 by , 15 years ago
I'm waiting with the modifications of the logging code in the patch till the logging code lands in trunk.
comment:10 by , 15 years ago
| Summary: | add support for STATIC_URL and STATIC_ROOT → Ease handling of static files (e.g. included in apps) |
|---|
by , 15 years ago
| Attachment: | 12323.5.diff added |
|---|
removed logging again and fixed a few other things
comment:11 by , 15 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
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.