django-始终从远程媒体_url而不是本地访问静态/媒体文件访问静态/媒体文件。
我有一个在服务器上运行的Django应用程序,我想继续使用runserver
命令在本地处理它。我的问题涉及使用常见静态文件和媒体文件的使用。 Media 文件夹内容在生产中经常更改,每次我要在本地开发DEV并将其添加到我的计算机上的Media_root
路径时,我必须从服务器下载这些媒体文件。
该数据库对于DEV和生产环境都是常见的,因为它是服务器上的MySQL主机。
如何在本地模式下告诉Django在我的域名而不是本地主机上查找静态和媒体文件? 喜欢https://example.com/media/
而不是: https://127.0.0.1:8000/media/
编辑:Module django-storages
一段时间后,我终于找到了一个模块,似乎与我在寻找的东西保持一致,django-storages具有其“ ftp'函数”',但是真的很虚弱,我找不到任何教程来解释我想实现的目标。
DEFAULT_FILE_STORAGE = 'storages.backends.ftp.FTPStorage'
FTP_STORAGE_LOCATION = 'ftp://user:password@host:21/media'
当我在本地工作时,我应该将哪种配置添加到设置文件中以获取Media_root寻找此位置?
I have a Django app running on a server and I would like to continue working on it locally with the runserver
command. My problem concern the use of common static and media files. The media folder content changing frequently in production I have to download those media files from the server each time I want to dev locally and add those to the MEDIA_ROOT
path on my computer.
The database is common to both dev and production environment since it is a MySQL host on my server.
How can I tell Django in local mode to lookup static and media files on a remote url from my domain name instead of localhost?
Like https://example.com/media/
instead of :https://127.0.0.1:8000/media/
EDIT : module django-storages
After some time I finally find a module which seems aligned with what I'm looking for, django-storages with its 'FTP' functionnality' however the documentation is really weak and I can't find any tutorial explaining what I want to achieve.
DEFAULT_FILE_STORAGE = 'storages.backends.ftp.FTPStorage'
FTP_STORAGE_LOCATION = 'ftp://user:password@host:21/media'
What kind of configuration should I add to my settings file to get MEDIA_ROOT looking for this location when I'm working locally ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我真的不明白为什么
静态
必须将其处理相同 - 它们应该是您项目来源的一部分。因此本地存储应具有更高的优先级。但是,服务任何此类文件仍然只是在派遣URL,所以
您可以尝试这样的尝试:(
未对其进行测试)
redirectView docs 几乎相似的问题
I don't really understand why
static
files have to be treated the same - they are supposed to be a part of your project sources. So local storage should have a higher priority.But serving any of such files is still just URL dispatching, so instead of this:
you might try something like this:
(did not test it)
RedirectView docs almost similar question
您只需在主URL之后进行测试
You simply test in after main url