开发者

I can't login to my Django app when debug is set to False

开发者 https://www.devze.com 2022-12-27 03:47 出处:网络
Short Story: I get locked out of my Django app when Debug is set to False. Long story: Case 1 (the first time it happened):

Short Story: I get locked out of my Django app when Debug is set to False.

Long story:

Case 1 (the first time it happened):

  1. I enter my login info, but It just redirects to the login page.

  2. I restart the server, try to login, and it works fine, I get in.

  3. a few hours later I come back, log out, try to log back in and I can't. It just redirects to the login page.

Case 2 (I figure out how to provoke the login failure):

  1. I restart the server and am able to login to the site.
  2. I log in and log out several times, everything is fine.
  3. I go to a non-existing page and get a server error.
  4. I log out and try to log back in, and I can't, just get redirected back to the login page.

Case 3 (I can't provoke the login failure with Debug set to True): 1. I restart the server and am able to login to the site. 2. I log in and log out several times, everything is fine. 3. I go to a non-existing page and get a traceback. 4. I log out and log back in, everything works. 5. I wait and play a开发者_Go百科round with it and can't get the login to fail while in Debug mode.

Please help!


Do you have a custom 500 error handler set up? Is that doing something weird with the session, perhaps?


I was having the same problem. Here is what I did to fix it:

I realized the cookie session was saved twice... I don't know why but after many changes a finally get working... just set

SESSION_SAVE_EVERY_REQUEST = True
SESSION_COOKIE_NAME = 'something'

and thats all.


My problem was if I set SESSION_COOKIE_SECURE = True then I can't login in http mode.

I had to change it to SESSION_COOKIE_SECURE = False

Maybe you had this too?


I would guess that this is related to errors in admin classes requiring the devserver to be restarted to continue.

As nothing is being reportedm I would try removing all of your admin.py definitions and just use the basic admin.site.register(SomeModel) for everything and seeing if it still happens, then add them back in until it re-occurs.


Make sure the urls.py file imports everything from django.conf.urls.defaults.

You may have explicitly imported certain methods such as patterns and include (as I did to combat PyDev's 'wild import' warning messages). As a result, crucial statements that assign Django's default handlers to 404 and 500 HTTP error codes will be omitted. This is obviously undesired and leads to the odd behavior described in the question.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号