Serving 2 django sites with the same code

拥有回忆 提交于 2019-12-11 06:37:31

问题


I'm serving a django site with apache and wsgi using an apache config as follow:

  Alias /media/ /var/www/media/
  Alias /files/ /var/www/files/
  WSGIDaemonProcess fc processes=5 threads=5 display-name=%{GLOBAL}
  WSGIProcessGroup fc
  WSGIScriptAlias / /home/path/to/django.wsgi

The app is served in the root directory of the host. I'd like now to change this so I can serve it at http://host/app1 and another one, with a different django setting, at http://host/app2

How can I change the config to do this?

Thanks


回答1:


You'll need a set of WSGI* directives for each project. That second parameter to WSGIScriptAlias tells Apache where the project lives in the tree; WSGI removes this prefix before the URL is passed to Django's URL resolver.

For example:

WSGIDaemonProcess app1 threads=15
WSGIScriptAlias /app1 /var/www/django_project1/django.wsgi
<Location /app1>
WSGIProcessGroup app1
</Location>

WSGIDaemonProcess app2 threads=15
WSGIScriptAlias /app2 /var/www/django_project2/django.wsgi
<Location /app2>
WSGIProcessGroup app2
</Location>

I haven't tried to optimize this; there may be a better way. But this should get you running.




回答2:


You may try to make other folder with second settings.py and create symbolic links to your apps, locales, static, templates, urls.py etc.

I have multiple projects using same apps so I've put them in standalone folder which i added to python path. I also use same database for both sites, but i have different SITE_ID so i can specify wchich site i want to have my content. This way i can have totally different websites using different templates, styles and images having the same content. If JS scripts are the same on both sites i create a symlink.



来源:https://stackoverflow.com/questions/5898762/serving-2-django-sites-with-the-same-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!