Multiple settings files with sites framework

19 Aufrufe
Direkt zur ersten ungelesenen Nachricht

sbarnett

ungelesen,
17.04.2018, 08:23:5417.04.18
an Django users
What is the best way to structure multiple settings files when using the Sites framework?

I've already got a base settings file along with a local, staging and production file which inherits from this and makes some changes/additions.

But now I need to use the Sites framework so I need another bunch of files that set the relevant SITE_ID, change the TEMPLATES directory etc.

I'm just not sure how to lay all of this out so that the site settings files can inherit (and then potentially override) the correct settings from local, staging or production.

Any ideas?

Mike Dewhirst

ungelesen,
17.04.2018, 23:53:5617.04.18
an django...@googlegroups.com
I ship staging.py (has SITE_ID = 2)  and production.py (has SITE_ID = 1)
to both machines and use wsgi.py to select the correct one. Here is mine ...

import os
import sys
from socket import gethostname

from django.core.wsgi import get_wsgi_application

# hard coded paths in buildbot master.cfg
project = "ssds"
srvroot = "/var/www"
site_root = "%s/%s" % (srvroot, project)   # as per bot master.cfg

hname = gethostname()
if "pq4" in hname:
    site = "production"
elif "pq3" in hname:
    site = "staging"
else:
    site = "dev"

if site_root not in sys.path:
    sys.path.insert(0, site_root)

os.environ["DJANGO_SETTINGS_MODULE"] = "%s.settings.%s" % (project, site)
os.environ["PYTHON_EGG_CACHE"] = site_root

# this is the public API - returns django.core.handlers.wsgi.WSGIHandler()
application = get_wsgi_application()





>
> Any ideas?
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f72d6853-e16d-4d82-b2f5-fede38ea9f63%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/f72d6853-e16d-4d82-b2f5-fede38ea9f63%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Simon Barnett

ungelesen,
18.04.2018, 09:48:2918.04.18
an Django users
Ah, I think you've slightly misunderstood me.

I already have staging and production sites and settings files - I don't use the Sites framework for that - I just use the DJANGO_SETTINGS_MODULE to control which settings file to use.

But now, I need to start using the Sites framework to serve mutliple (live) sites using the same code and database. So a.com and b.com, both displaying different data from the same database.

For this, I think I'll need a settings file for each site - a.py and b.py - which define the SITE_ID and templates dir for each one. But then, how do I structure all these settings files I now have?

base.py - main settings
staging.py - staging settings
production.py - production settings
a.py - settings for a.com
b.py - settings for b.com

and how do I use them for local development?

Mike Dewhirst

ungelesen,
18.04.2018, 20:40:3818.04.18
an django...@googlegroups.com, Simon Barnett
On 18/04/2018 6:09 PM, Simon Barnett wrote:
> Ah, I think you've slightly misunderstood me.
>
> I already have staging and production sites and settings files - I
> don't use the Sites framework for that - I just use the
> DJANGO_SETTINGS_MODULE to control which settings file to use.
>
> But now, I need to start using the Sites framework to serve mutliple
> (live) sites using the same code and database. So a.com and b.com,
> both displaying different data from the same database.
>
> For this, I think I'll need a settings file for each site - a.py and
> b.py - which define the SITE_ID and templates dir for each one. But
> then, how do I structure all these settings files I now have?
>
> base.py - main settings
> staging.py - staging settings
> production.py - production settings
> a.py - settings for a.com
from production import *

> b.py - settings for b.com
from production import *

> and how do I use them for local development?

dev-a.py
from a import *

dev-b.py
from b import *
> > an email to django-users...@googlegroups.com <javascript:>
> > <mailto:django-users...@googlegroups.com <javascript:>>.
> > To post to this group, send email to django...@googlegroups.com
> <javascript:>
> > <mailto:django...@googlegroups.com <javascript:>>.
> <https://groups.google.com/group/django-users>.
> <https://groups.google.com/d/msgid/django-users/f72d6853-e16d-4d82-b2f5-fede38ea9f63%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/07686134-881e-4bb0-aff9-fb35b9e4f988%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/07686134-881e-4bb0-aff9-fb35b9e4f988%40googlegroups.com?utm_medium=email&utm_source=footer>.

m1chael

ungelesen,
18.04.2018, 22:39:1918.04.18
an django...@googlegroups.com
I have an apps dir, and several project dirs (one per domain/subdomain)

the settings files for  are kinda like this:

from mainproject.settings import *

then i'll just re-define what i'm overwriting.. like SITE_ID, or urls, etc..

it seems to work good for me

    > <mailto:django-users+unsubscrib...@googlegroups.com <javascript:>>.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com <mailto:django-users+unsubscrib...@googlegroups.com>.
To post to this group, send email to django...@googlegroups.com <mailto:django-users@googlegroups.com>.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten