django - CSRF verification Failed - Referer is insecure while host is secure -
i upgraded django 1.8 1.9. afterwards, error on localhost after django admin login:
referer checking failed - referer insecure while host secure
.
everything works fine in production. below snippet of settings.py file:
secure_proxy_ssl_header = ('http_x_forwarded_proto', 'https') session_cookie_secure = true csrf_cookie_secure = true
those lines in settings.py
file fine on production because you're using ssl certificate attached domain. however, on local you're using http://localhost:8000
or similar. if try connect via https://localhost:{{your_port_number}}
you'll error err_ssl_protocol_error
.
the issue in lines 167-168 of django/django/middleware/csrf.py. when you're using https
on production, request.is_secure()
returning true
...which requires http_referer
true or you'll error referenced.
one solution adjust settings.py
file depending on whether you're in local or production environment. way can add 3 lines settings_production.py
file imports other settings common both localhost , production server. localhost use different set of settings don't include lines.
Comments
Post a Comment