'''
STATIC_URL = '/static/'
MEDIA_URL = os.path.join(STATIC_URL, 'upped') + '/'
'''
leads to the development server refusing to serve media files when
staticfiles is installed even if a URL route is specified since the
staticfiles.handlers.StaticFilesHandler takes over.
While there is a check in staticfiles warning that MEDIA_URL should not be
equals to STATIC_URL, it does not warn about the cases where STATIC_URL is
a prefix of MEDIA_URL. This also does not seem to be documented anywhere
that I've seen.
The suggestion to allow this seems to have been closed wontfix in
https://code.djangoproject.com/ticket/15199 so I won't attempt a patch.
Adding a check for this case does seem easy though, and I've attached a
patch that adds a warning to this ticket. The documentation could also
mention that adding an explicit url pattern for static and running
```python manage.py runserver --nostatic``` can be used as a workaround.
--
Ticket URL: <https://code.djangoproject.com/ticket/29570>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "staticwarning.patch" added.
* component: Documentation => Core (System checks)
* version: 2.0 => master
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted
Comment:
> The documentation could also mention that adding an explicit url
pattern for static and running python manage.py runserver --nostatic can
be used as a workaround.
The conclusion from #15199 was that having MEDIA_URL inside STATIC_URL
(MEDIA_ROOT inside STATIC_ROOT?) is a pattern that we want to avoid, so I
don't think documenting a workaround is consistent with that.
Rather, strengthening the system check seems reasonable. (The patch checks
media is not inside static. Is it worth doing the opposite too?)
The MEDIA_ROOT docs already say:
> MEDIA_ROOT and STATIC_ROOT must have different values. ...
With the extra check this ''may'' be enough (I've always read it that way)
but if an alternative phrasing that says "not inside each other too" that
is both short and precise can be found then maybe we can update that as
well.
--
Ticket URL: <https://code.djangoproject.com/ticket/29570#comment:1>
* needs_tests: 0 => 1
Comment:
Alejandro, could you create a Pull Request on GitHub with your patch,
adding at least a test case, so we can review? Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/29570#comment:2>
Comment (by Alejandro Dubrovsky):
Done: https://github.com/django/django/pull/10196
As mentioned in the pull request, the check only runs when staticfiles
takes over (ie in DEBUG mode when staticfiles is in the INSTALLED_APPS),
since that is when the problem occurs and that's what the warning warns
about.
--
Ticket URL: <https://code.djangoproject.com/ticket/29570#comment:3>
* cc: Herbert Fortes (added)
Comment:
Hi,
I ran the tests (./runtests.py) without a problem.
I have one minor suggestion. Instead of `\` use `()` to break a line:
{{{#!python
if (settings.MEDIA_URL and settings.STATIC_URL and
settings.MEDIA_URL.startswith(settings.STATIC_URL)):
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29570#comment:4>
Comment (by Alejandro Dubrovsky):
Modified to use parenthesis instead of a continuation marker to break up
the line as per Herbert's suggestion.
--
Ticket URL: <https://code.djangoproject.com/ticket/29570#comment:5>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"108c04f572ccca74258c4d2024aef61270a5b083" 108c04f]:
{{{
#!CommitTicketReference repository=""
revision="108c04f572ccca74258c4d2024aef61270a5b083"
Fixed #29570 -- Added check that MEDIA_URL isn't in STATIC_URL.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29570#comment:6>