Running Django 1.2.5 on a Linux server with Apache2, and for some reason, Django seems to be unable to store CSRF or session cookies. So when I try to log into the Django admin, it gives me a CSRF validation error when submitting the login form. Has anyone opposed this and found a solution?
I can make a valid post when I try this at the address of my VPS that was provided by my host. Example: vps123.hostdomain.com/admin/, and cookies will be set for this domain. However, when I go to www.sitedomain.com/admin/ and try to log in, I get a CSRF 403 error stating that the cookie does not exist, and when I check the files of my browsers, they are not installed.
I tried to set 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 displays in POST.
I have cookies. I tried this on several browsers and machines.
There is a proxy server on www.sitedomain.com, which I think may be part of the problem. Anyone with experience with proxies and Django can shed some light on this.
My apache2 configurator:
NameVirtualHost *:80 <VirtualHost *:80> ServerName www.sitedomain.com ServerAlias www.sitedomain.com <Location "/"> Options FollowSymLinks SetHandler python-program PythonInterpreter nzsite PythonHandler django.core.handlers.modpython PythonDebug On PythonPath "['/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.com ServerAlias othersite.sitedomain.com <Location "/"> Options FollowSymLinks SetHandler python-program PythonInterpreter ausite PythonHandler django.core.handlers.modpython PythonDebug On PythonPath "['/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>
source share