Running Django 1.2.5 on a Linux server with Apache2 and for some reason Django seems like it cannot store CSRF or Session cookies. Therefore when I try to login to the Django admin it gives me a CSRF verification error upon submitting the login form. Has anyone come up against this and found a solution?
I AM able to make a valid post when i try this at the url of my VPS that was provided by my host. Example: vps123.hostdomain.com/admin/ and for that domain the cookies DO get set. However, when I go to www.sitedomain.com/admin/ and try to login I get a CSRF 403 error saying the cookie is not there and when I check in my browsers cookies they are not set.
I have tried setting the following in my settings file:
SESSION_COOKIE_DOMAIN = 'www.sitedomain.com'
CSRF_COOKIE_DOMAIN = 'www.sitedomain.com'
Also tried:
SESSION_COOKIE_DOMAIN = 'vps123.hostdomain.com'
CSRF_COOKIE_DOMAIN = 'vps123.hostdomain.com'
I have 'django.middleware.csrf.CsrfViewMiddleware' added to my MIDDLEWARE_CLASSES in settings.py and there is a CSRF token in the form and it shows up in the POST.
I have cookies enabled. I have tried this on multiple browsers and machines.
There is a varnish proxy server sitting in front of www.sitedomain.com that I think may be part of the problem. Anyone with experience using proxy servers and Django may be able to shed some light on that.
My apache2 config:
NameVirtualHost *:80<VirtualHost *:80>ServerName www.sitedomain.comServerAlias www.sitedomain.com<Location "/">Options FollowSymLinksSetHandler python-programPythonInterpreter nzsitePythonHandler django.core.handlers.modpythonPythonDebug OnPythonPath "['/var/www/django_projects', '/var/www', '/usr/lib/python2.6/dist-packages'] + sys.path"SetEnv DJANGO_SETTINGS_MODULE project_one.settings</Location><location "/phpmyadmin">SetHandler None</location>
</VirtualHost><VirtualHost *:80>ServerName othersite.sitedomain.comServerAlias othersite.sitedomain.com<Location "/">Options FollowSymLinksSetHandler python-programPythonInterpreter ausitePythonHandler django.core.handlers.modpythonPythonDebug OnPythonPath "['/var/www/django_projects', '/var/www', '/usr/lib/python2.6/dist-packages'] + sys.path"SetEnv DJANGO_SETTINGS_MODULE project_two.settings</Location><location "/phpmyadmin">SetHandler None</location>
</VirtualHost>