无法登录Django管理员 [英] Can't sign in to Django admin
问题描述
我不知道是否相关,但我也不能运行django-admin.py命令。这是我迄今为止所做的:
$ django-admin.py validate
错误:设置不能导入,因为环境变量DJANGO_SETTINGS_MODULE未定义。
$ export DJANGO_SETTINGS_MODULE = mysite.settings
$ django-admin.py validate
错误:无法导入设置mysite.settings(是否在sys.path上?它是否具有语法错误?):没有名为mysite.settings的模块
sys.path显示['/ Users / joerobinson / Sites / django / mysite'...(路径中的其他东西)]
有没有其他我需要做的注册mysite模块?
python manage.py runserver工作正常。
结论
对于问题关于登录到django管理员,我没有django.contrib.auth.backends.ModelBackend包含在我的AUTHENTICATION_BACKENDS中 - 添加这个允许我登录管理员。
我仍在处理django-admin.py配置问题(这似乎不相关),并且会在一个单独的问题中重新打开它。
mysite的父文件夹
是需要在python路径上。将 mysite
本身添加到您的python路径将暴露 mysite
的内容,而不是 mysite
module to python。 至于runserver工作/密码不工作,我没有线索。你有任何定制任何身份验证?
您可以启动shell并尝试与超级用户进行身份验证吗?
http://docs.djangoproject.com/en/dev /topics/auth/#django.contrib.auth.authenticate
您在评论中说is_staff被设置得恰当...同样的问题。 - 这是否意味着您可以使用第一个超级用户登录以设置 is_staff
??
I can't sign in to Django admin with any of the superusers I've created. Tried creating new superusers, changing passwords, etc. - no error messages for any of these processes, but still can't sign in.
I'm not sure if it's related, but I also can't run django-admin.py commands. Here is what I've done so far:
$ django-admin.py validate
Error: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
$ export DJANGO_SETTINGS_MODULE=mysite.settings
$ django-admin.py validate
Error: Could not import settings 'mysite.settings' (Is it on sys.path? Does it have syntax errors?): No module named mysite.settings
sys.path shows ['/Users/joerobinson/Sites/django/mysite' ... (other stuff on path)]
Is there something else I need to do to register the mysite module?
python manage.py runserver works fine.
Conclusion
For the question about logging in to django admin, I did not have django.contrib.auth.backends.ModelBackend included in my AUTHENTICATION_BACKENDS - adding this allowed me to sign in to admin.
I'm still working on the django-admin.py configuration question (which appears to not be related), and will reopen it in a separate question.
Well, to answer one of your questions, the parent folder of mysite
is what needs to be on the python path. Adding mysite
itself to your python path will expose the contents of mysite
, not the mysite
module to python.
As for runserver working / passwords not working, I haven't a clue. Have you customized anything with authentication?
Can you start the shell and try authenticating with your superuser? http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.authenticate
You said in a comment that "is_staff was set appropriately... same problem." -- does that mean you were able to log in with the first superuser to set is_staff
??
这篇关于无法登录Django管理员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!