On 12/11/2018 9:00 AM, Gear Crew wrote:
> when i can use it in any project?
Have a look at wsgi.py created by django-admin when you start a new
project. That should let you understand how to use Django in multiple
projects. In my case, I use different virtualenvs and separate
installations of Django in development. In production I have a single
environment with two running projects ie two Django websites in separate
virtual hosts each with their environment variables managed by Apache.
I'm not sure it is the best way to do it but I haven't encountered any
problems yet.
Here is an example of one of my wsgi.py files ...
from __future__ import unicode_literals, absolute_import, division
import os
import sys
from socket import gethostname
from django.core.wsgi import get_wsgi_application
project = "xxxx"
srvroot = "/var/www"
site_root = "%s/%s" % (srvroot, project)
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()
>
> On Sunday, 11 November 2018 23:57:58 UTC+2, Mike Dewhirst wrote:
>
> On 12/11/2018 3:24 AM, Gear Crew wrote:
> > I want to understand why do that
>
> Because Django needs to know which settings module to use so it
> can find
> all your apps and models.
>
> It was designed that way so that a single installation of Django
> could
> be used for multiple projects.
>
> > Screenshot from 2018-11-11 18-09-56.png
> >
> >
> > --
> > 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 <javascript:>
> > <mailto:
django-users...@googlegroups.com <javascript:>>.
> <javascript:>
> > <mailto:
django...@googlegroups.com <javascript:>>.
> <
https://groups.google.com/group/django-users>.
> <
https://groups.google.com/d/msgid/django-users/082717ec-8e88-445d-a0c1-2032f2de9144%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>.
>
https://groups.google.com/d/msgid/django-users/50608575-2738-4f89-bcb1-5ee55c8d062a%40googlegroups.com
> <
https://groups.google.com/d/msgid/django-users/50608575-2738-4f89-bcb1-5ee55c8d062a%40googlegroups.com?utm_medium=email&utm_source=footer>.