Have django serving different settings file & database based on subdomains. The virtual host entries are manually added to apache.
There are currently two subdomains with different databases. First one is working okay, the second one is not displaying any css/images.
Apache configuration is as, there are two of them
<VirtualHost *:80>
ServerName test.domain.com
ServerAlias test.domain.com
DocumentRoot /var/www/site/
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE site.settings.test
PythonDebug On
PythonPath "['/var/www/site/'] + sys.path"
</location>
<location "/public/media">
SetHandler None
</location>
<location "/public/admin_media">
SetHandler None
</location>
<location "/static">
SetHandler None
</location>
</V开发者_开发知识库irtualHost>
The content of subdomain having issues with displaying css/images , are in /public/media folder. If accessed directly via http://test.domain.com/public/media/images/image.jpg , the images are there.
1) Note that you are not loading the default "settings.py", but "settings/test.py".
SetEnv DJANGO_SETTINGS_MODULE site.settings.test
So maybe it should be:
SetEnv DJANGO_SETTINGS_MODULE site.settings
or
SetEnv DJANGO_SETTINGS_MODULE site.settings.production
2) Make sure you have this, in whatever your settings file is:
DEBUG = False
MEDIA_URL = "/public/media"
ADMIN_MEDIA_PREFIX = "/public/admin_media"
I suggest you uses two different virtualhosts for the two different subdomains.
Subdomain test1.domain.com ServerName test1.domain.com
DocumentRoot /var/www/site/
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE site.settings.test
PythonDebug On
PythonPath "['/var/www/site/'] + sys.path"
</location>
<location "/public/media">
SetHandler None
</location>
<location "/public/admin_media">
SetHandler None
</location>
<location "/static">
SetHandler None
</location>
</VirtualHost>
Subdomain test2.domain.com ServerName test2.domain.com
DocumentRoot /var/www/site/
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE site.settings.test
PythonDebug On
PythonPath "['/var/www/site/'] + sys.path"
</location>
<location "/public/media">
SetHandler None
</location>
<location "/public/admin_media">
SetHandler None
</location>
<location "/static">
SetHandler None
</location>
</VirtualHost>
It was session/cookie problem. Added SESSION_COOKIE_DOMAIN to settings.py with subdomain , seems to work fine now.
精彩评论