gpt4 book ai didi

django - 如果MEDIA_URL在STATIC_URL内,则runserver无法提供媒体

转载 作者:行者123 更新时间:2023-12-02 11:20:31 29 4
gpt4 key购买 nike

我的配置如下:

STATIC_URL = '/static/'
MEDIA_URL = '/static/media/'

由于我将django 2.1升级到2.2,所以我得到了:
"runserver can't serve media if MEDIA_URL is within STATIC_URL."
django.core.exceptions.ImproperlyConfigured: runserver can't serve media if MEDIA_URL is within STATIC_URL.

我了解错误。我的问题是“为什么不”?您有非常正当的理由希望将媒体作为静态子目录。

另外,在2.2版发行说明中几乎没有提及这一重大更改: https://docs.djangoproject.com/en/3.0/releases/2.2/

最佳答案

响应此票证#29570: Add check that MEDIA_URL is not inside STATIC_URL.发出了此警告。
也引用#15199: Allow MEDIA_ROOT inside STATIC_ROOT

After further IRC discussion with jezdez, closing this wontfix. Supporting a configuration with MEDIA_ROOT inside STATIC_ROOT introduces a number of additional complexities and couplings between staticfiles and the MEDIA_* settings, which we are trying to avoid, and it's not clear what meaningful benefits it buys us. The main mentioned benefit was to only require one alias on the front-end webserver: that seems minor, since an alias is e.g. just one line in an nginx conf file. In any case, the same result can be achieved by putting MEDIA_ROOT and STATIC_ROOT side by side in a parent directory, and aliasing the front-end webserver to that parent directory.


因此,基本上,您可以:
STATIC_URL = '/static/static/'
MEDIA_URL = '/static/media/'

关于django - 如果MEDIA_URL在STATIC_URL内,则runserver无法提供媒体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59469585/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com