无法在Django中进行身份验证

时间:2018-10-17 10:32:48

标签: django django-authentication

我已经成功地使用django的Authentication后端对用户进行身份验证,并且具有经过修改的模板系统来执行此操作。一切似乎都正常。昨天,在尝试发布网站的生产版本时,我做了两项修改:

  1. 将LOGIN_REDIRECT_URL从/ appointments更改为/ clinic这两个都是我项目中的两个独立应用。
  2. 我添加了SECURE_SSL_REDIRECT = True以将http重定向到https。

这些之后,我将提交推送到git development分支。昨天我没有发现任何错误。

今天,我尝试运行开发服务器,并发现无法登录。无法识别我的超级用户登录密码。因此,我使用manage.py changepasswordmanage.py passwd重设密码。但是它仍然无法登录。没有显示明显的错误(Debug仍设置为True)。

我创建了一个新的超级用户,但是即使登录失败。在前端出现错误Your username and password didn't match. Please try again.

当尝试登录django提供的管理界面时,我没有得到任何错误:

$ python3 manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
October 17, 2018 - 16:26:29
Django version 2.1.2, using settings 'myappointments.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[17/Oct/2018 16:26:31] "GET / HTTP/1.1" 302 0
[17/Oct/2018 16:26:31] "GET /accounts/login/?next=/clinic HTTP/1.1" 200 5469
[17/Oct/2018 16:26:31] "GET /appointments/static/clinic/css/bootstrap.css HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/css/datepicker.0.6.5.css HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/css/jquery-ui/jquery-ui.css HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/css/fontawesome.5.2.0.css HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/css/fullcalendar.css HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/css/jquery-ui/jquery-ui.theme.css HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/css/jquery-ui/jquery-ui.structure.css HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/css/mytheme.css?dev= HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/registration/css/themedlogin.css HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/css/calcustomcolors.css?dev= HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/jquery-ui/jquery-ui.js?dev= HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/popper.min.js HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/jquery-3.3.1.min.js HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/bootstrap.min.js HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/notify.0.4.2.js HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/datepicker.0.6.5.js HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/search.js?dev= HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/lib/moment.min.js HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/fullcalendar.js HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/appointment.js?dev= HTTP/1.1" 304 0
[17/Oct/2018 16:26:32] "GET /appointments/static/clinic/icons/health-sign.png HTTP/1.1" 304 0
[17/Oct/2018 16:26:39] "POST /accounts/login/ HTTP/1.1" 302 0
[17/Oct/2018 16:26:39] "GET /clinic HTTP/1.1" 301 0
[17/Oct/2018 16:26:40] "GET /clinic/ HTTP/1.1" 302 0
[17/Oct/2018 16:26:40] "GET /accounts/login/?next=/clinic HTTP/1.1" 200 5469
[17/Oct/2018 16:26:44] "GET /admin/ HTTP/1.1" 302 0
[17/Oct/2018 16:26:44] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1862
[17/Oct/2018 16:26:44] "GET /appointments/static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 8192
[17/Oct/2018 16:26:50] "POST /admin/login/?next=/admin/ HTTP/1.1" 302 0
[17/Oct/2018 16:26:50] "GET /admin/ HTTP/1.1" 302 0
[17/Oct/2018 16:26:50] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1862

我可能应该提到在开发机器上,我使用本地python3版本,而在生产环境中,我使用virtualenv。

1 个答案:

答案 0 :(得分:0)

您可能应该为生产和开发环境设置不同的设置。看一下这个结构。这是一篇不错的文章。 multiple settings

mysite/
 |-- mysite/
 |    |-- __init__.py
 |    |-- settings/
 |    |    |-- __init__.py
 |    |    |-- base.py
 |    |    |-- ci.py
 |    |    |-- development.py
 |    |    |-- production.py
 |    |    +-- staging.py
 |    |-- urls.py
 |    +-- wsgi.py
 +-- manage.py

例如,您可以将SECURE_SSL_REDIRECT = True放在production.py文件上。想法是根据您的环境需要进行设置。