简体   繁体   English

'django.contrib.staticfiles'的问题,

[英]Issues with 'django.contrib.staticfiles',

I have a website that works fine on my 'production server' with the url being something akin to: 我有一个网站可以在我的“生产服务器”上正常运行,其网址类似于以下内容:

https://mymain.site.com https://mymain.site.com

I have had my sys admins build a site out for development and that url is: 我的系统管理员已建立了一个网站进行开发,该网址为:

https://mymain.site.com/development https://mymain.site.com/development

It is a different IP address, but I believe the URL is wrecking havoc on django routing. 这是一个不同的IP地址,但我相信该URL会对Django路由造成严重破坏。 Mostly I notice it in the static section of it. 通常,我会在它的静态部分注意到它。

If I goto the development server settings and change the static url to: 如果我转到开发服务器设置并将静态URL更改为:

/development/static/ /开发/静态/

instead of /static/ like it was on production 而不是/ static /

None of my static files are found. 找不到我的静态文件。 Since the development server is a VM copy the root on the server for static files is the same. 由于开发服务器是VM复制,静态文件在服务器上的根目录是相同的。 So if I run with the /development/static as the dev url it fails to load resources. 因此,如果我将/ development / static作为dev url运行,它将无法加载资源。 If I run on my development server with the url being /static/ I am 90% sure it is grabbing the static files from the production server (at a different ip/url). 如果我在开发服务器上运行的URL为/ static /,则我90%确信它正在从生产服务器获取静态文件(位于其他ip / url)。 Not totally sure what the fix is here? 不能完全确定这里的解决方案吗? I am loking for any kind of ideas. 我正在寻找任何想法。

I suspect if the url of my development server was something more akin to: 我怀疑开发服务器的网址是否更类似于:

https://mymain.site.for.development/ HTTPS://mymain.site.for.development/

then this would work right out of the box from the code copied from the VM just repointing a few things. 那么这可以直接从VM复制的代码中直接进行一些操作。

So what am I missing to get this to work with the right static files? 那么,要使它与正确的静态文件一起使用,我缺少什么呢?

I use a CDN for my static file hosting and this is how I have my settings.py file setup: 我将CDN用于静态文件托管,这就是我的settings.py文件设置的方式:

STATIC_HOST = 'https://cdn.host.com' if not DEBUG else ''
STATIC_URL = STATIC_HOST + '/static/'

When I'm developing I'll set DEBUG = True and everything works as expected. 在开发时,我将设置DEBUG = True ,一切都会按预期进行。 I would imagine you would have to do something like this: 我想您将必须执行以下操作:

STATIC_HOST = 'https://mymain.site.com' if not DEBUG else 'https://mymain.site.com/development'
STATIC_URL = STATIC_HOST + '/static/'

See if something like that would work. 看看类似的东西是否行得通。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM