Django SECURE_SSL_REDIRECT 设置报错问题

本文解决了一个常见的开发问题:当你在本地使用HTTP测试,但配置文件中误设为HTTPS时,浏览器会出现警告。文章详细介绍了如何通过清除浏览器缓存来解决这个问题,并保持SECURE_SSL_REDIRECT设置为False。

你可能在部署时,这样设置了:

SECURE_SSL_REDIRECT = True  # 所有的HTTP将重定向到HTTPS

然后,你再自己电脑测试时,这样设置:

SECURE_SSL_REDIRECT = False

结果,报这个错:

 You're accessing the development server over HTTPS, but it only supports HTTP.

解决办法:

把你浏览器缓存清理一下就OK了,当然这个设置不变:

SECURE_SSL_REDIRECT = False
(venv) C:\Users\lenovo\PycharmProjects\gaitTest>python manage.py check --deploy SystemCheckError: System check identified some issues: ERRORS: admin.LogEntry.user: (fields.E300) Field defines a relation with model 'app.Doctor', which is either not installed, or is abstract. WARNINGS: ?: (security.W004) You have not set a value for the SECURE_HSTS_SECONDS setting. If your entire site is served only over SSL, you may want to consider setting a value and enabling HTTP Strict Transport Security. Be sure to read the documentation first; enabling HSTS carelessly can cause serious, irreversible problems. ?: (security.W008) Your SECURE_SSL_REDIRECT setting is not set to True. Unless your site should be available over both SSL and non-SSL connections, you may want to either set this setting True or configure a load balancer or reverse-proxy server to redirect all connections to HTTPS. ?: (security.W009) Your SECRET_KEY has less than 50 characters, less than 5 unique characters, or it's prefixed with 'django-insecure-' indicating that it was generated automatically by Django. Please generate a long and random value, otherwise many of Django's security-critical features will be vulnerable to attack. ?: (security.W012) SESSION_COOKIE_SECURE is not set to True. Using a secure-only session cookie makes it more difficult for network traffic sniffers to hijack user sessions. ?: (security.W016) You have 'django.middleware.csrf.CsrfViewMiddleware' in your MIDDLEWARE, but you have not set CSRF_COOKIE_SECURE to True. Using a secure-only CSRF cookie makes it more difficult for network traffic sniffers to steal the CSRF t oken. ?: (security.W018) You should not have DEBUG set to True in deployment. System check identified 7 issues (0 silenced).
最新发布
05-26
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值