简体   繁体   中英

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

I have had my sys admins build a site out for development and that url is:

https://mymain.site.com/development

It is a different IP address, but I believe the URL is wrecking havoc on django routing. Mostly I notice it in the static section of it.

If I goto the development server settings and change the static url to:

/development/static/

instead of /static/ like it was on production

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. So if I run with the /development/static as the dev url it fails to load resources. 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). 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/

then this would work right out of the box from the code copied from the VM just repointing a few things.

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:

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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