First of all, I am a newbie. I'm running Ubuntu 11.04 which comes with Python 2.7 so I installed Python2.5 in different dir to run Django-Non-Rel on Google App Engine. I did the Guestbook tutorial and now I am trying to add admin access but when I type in correct username:password Django thinks its incorrect. It doesn't even work when deployed to GAE. If you know please poke me in the right direction.
首先,我是新手。我正在运行带有Python 2.7的Ubuntu 11.04,所以我在不同的目录中安装了Python2.5,以便在Google App Engine上运行Django-Non-Rel。我做了留言簿教程,现在我正在尝试添加管理员权限,但是当我输入正确的用户名时:密码Django认为它不正确。它在部署到GAE时甚至不起作用。如果你知道的话,请把我指向正确的方向。
I added:
我补充说:
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
)
INSTALLED_APPS = (
...
'django.contrib.admin',
....
)
EDIT
I also added
编辑我也补充说
url(r'^admin/', include(admin.site.urls)),
url(r'^ admin /',include(admin.site.urls)),
to urls.py in subproject directory.
EOEDIT
到子项目目录中的urls.py. EOEDIT
Then I created superuser and synced databases:
然后我创建了超级用户和同步数据库:
> python2.5 xxx-xxx-guestbook/manage.py createsuperuser python2.5
> xxx-xxx-guestbook/manage.py syncdb
Then ran the app and can't login. I created multiple different supersusers always with the same result.
然后运行应用程序,无法登录。我创建了多个不同的超级用户,结果总是相同的。
EDIT2
EDIT2
Thanks everyone for trying to help but unfortunately neither of the offered solutions fixed the problem. I have decided to first learn Django on its own and then maybe switch to GAE Django-nonrel, so the question is not relevant anymore. Should I still pick one answer to give someone some points?
感谢大家尝试提供帮助,但不幸的是,所提供的解决方案都没有解决问题。我决定先自己学习Django,然后转换到GAE Django-nonrel,所以这个问题不再适用了。我还应该选择一个答案给某人一些积分吗?
8 个解决方案
#1
3
Not too sure on this, but syncdb might remove the superuser you just created. Try creating a superuser when syncdb prompts you to.
对此不太确定,但syncdb可能会删除刚刚创建的超级用户。尝试在syncdb提示时创建超级用户。
Otherwise, take a look at the user model in ./manage.py shell
. Check User.objects.all()[0].is_superuser
.
否则,请查看./manage.py shell中的用户模型。检查User.objects.all()[0] .is_superuser。
#2
20
There is some kind of limitation in django-nonrel.
django-nonrel存在某种限制。
To create a superuser:
要创建超级用户:
- Stop the local webserver
- 停止本地Web服务器
-
Create the superuser
创建超级用户
python manage.py createsuperuser
-
Run the webserver again
再次运行Web服务器
python manage.py runserver
#3
5
Assuming you have the correct username and password, the only thing that will present the same behavior as a failed login is having is_staff=False
for the user in question.
假设您拥有正确的用户名和密码,那么唯一会出现与登录失败相同的行为的是相关用户的is_staff = False。
Go into your database and inspect the auth_user table. Make sure that is_staff
is set to TRUE
on the user you are using to log in.
进入数据库并检查auth_user表。确保用于登录的用户的is_staff设置为TRUE。
#4
4
In urls.py uncomment:
在urls.py取消注释:
# Uncomment the next line to enable the admin:
**# url(r'^admin/', include(admin.site.urls)),**
and that should make you good for the races :)
这应该会让你对比赛有好处:)
PS. do not forget to run a ./manage.py syncdb and it will ask to setup an admin user.
PS。不要忘记运行./manage.py syncdb,它会要求设置管理员用户。
#5
1
If you're an idiot, like me, you might be trying to login with your email rather than your username.
如果你是像我这样的白痴,你可能会尝试使用你的电子邮件而不是你的用户名登录。
I think I was doing this because when creating the superuser I remembered entering an email and not a username (because django offers you a username without having to type it), and perhaps the usual convention of using emails for usernames.. Man I feel stupid haha.
我想我是这样做的,因为在创建超级用户时我记得输入电子邮件而不是用户名(因为django为您提供了用户名而无需输入用户名),也许是使用电子邮件进行用户名的通常惯例。我觉得很愚蠢哈哈。
#6
1
I had met the same situation just as you. And I found I switched the authentication backend to
我和你一样遇到了同样的情况。我发现我将身份验证后端切换为
someproject.backends.EmailCheckmodelBackend
someproject.backends.EmailCheckmodelBackend
And in the settings.py I had added a line:
在settings.py中我添加了一行:
AUTHENTICATION_BACKENDS = ('someproject.backends.EmailCheckModelBackend',)
AUTHENTICATION_BACKENDS =('someproject.backends.EmailCheckModelBackend',)
And the backend is like:
而后端就像:
class EmailCheckModelBackend(ModelBackend):
def authenticate(self, username = None, password = None, is_staff = None):
try:
user = User.objects.get(email = username)
if user.check_password(password):
if is_staff is not None:
if user.is_staff == is_staff:
return user
else:
return None
return user
except User.DoesNotExist:
return None
You will find actually the username is forced to be alternated by 'email'. So you have to login your page with email account. If like
实际上,您会发现用户名*通过“电子邮件”进行交替。因此,您必须使用电子邮件帐户登录您的页面。如果喜欢
Username: someone@somewhere.com
用户名:someone@somewhere.com
password: password
密码:密码
Then it works. Hope this helpful for everyone.
然后它工作。希望这对每个人都有帮助。
#7
0
I had the same problem and could not understand why I could not login because all the settings were correct. However, I traced it to Django offering me a superuser name containing an initial capital letter, but actually saving the name as completely lowercase!
我有同样的问题,无法理解为什么我无法登录,因为所有设置都是正确的。但是,我跟踪它给Django提供了一个包含首字母大写字母的超级用户名,但实际上将名称保存为完全小写!
I naturally used the superuser name with capitals (as offered by Django) and authentication failed. When inspecting the data tables to check 'is_staff' etc I spotted the error. I know I was not mistaken because I repeated the setup process a couple of times and noted the superuser credentials to be sure of details like case.
我自然地使用超级用户名和大写字母(由Django提供)并且身份验证失败。在检查数据表以检查'is_staff'等时,我发现了错误。我知道我没有弄错,因为我重复了几次设置过程并注意到超级用户凭据以确保像case一样的细节。
So, the moral is be careful when accepting the default name offered by Django! It lies!
因此,在接受Django提供的默认名称时,道德要谨慎!它在于!
#8
0
It's not that difficult to fix. First of all make sure to allow your default settings
修复起来并不困难。首先,请确保允许您的默认设置
(DEBUG=TRUE,ALLOWED_HOST=[ ])
in the settings file of your website folder.
在您的网站文件夹的设置文件中。
Get into your website folder (using the command prompt), and type the following command:
进入您的网站文件夹(使用命令提示符),然后键入以下命令:
$ python manage.py createsuperuser
name:
email:e.g fulluser@admin.com
password:
Go back into the browser and run the server. Set the username (not the email), alongside your password which you created earlier. It will surely work fine this time.
返回浏览器并运行服务器。设置用户名(而不是电子邮件)以及您之前创建的密码。这次肯定会工作正常。
#1
3
Not too sure on this, but syncdb might remove the superuser you just created. Try creating a superuser when syncdb prompts you to.
对此不太确定,但syncdb可能会删除刚刚创建的超级用户。尝试在syncdb提示时创建超级用户。
Otherwise, take a look at the user model in ./manage.py shell
. Check User.objects.all()[0].is_superuser
.
否则,请查看./manage.py shell中的用户模型。检查User.objects.all()[0] .is_superuser。
#2
20
There is some kind of limitation in django-nonrel.
django-nonrel存在某种限制。
To create a superuser:
要创建超级用户:
- Stop the local webserver
- 停止本地Web服务器
-
Create the superuser
创建超级用户
python manage.py createsuperuser
-
Run the webserver again
再次运行Web服务器
python manage.py runserver
#3
5
Assuming you have the correct username and password, the only thing that will present the same behavior as a failed login is having is_staff=False
for the user in question.
假设您拥有正确的用户名和密码,那么唯一会出现与登录失败相同的行为的是相关用户的is_staff = False。
Go into your database and inspect the auth_user table. Make sure that is_staff
is set to TRUE
on the user you are using to log in.
进入数据库并检查auth_user表。确保用于登录的用户的is_staff设置为TRUE。
#4
4
In urls.py uncomment:
在urls.py取消注释:
# Uncomment the next line to enable the admin:
**# url(r'^admin/', include(admin.site.urls)),**
and that should make you good for the races :)
这应该会让你对比赛有好处:)
PS. do not forget to run a ./manage.py syncdb and it will ask to setup an admin user.
PS。不要忘记运行./manage.py syncdb,它会要求设置管理员用户。
#5
1
If you're an idiot, like me, you might be trying to login with your email rather than your username.
如果你是像我这样的白痴,你可能会尝试使用你的电子邮件而不是你的用户名登录。
I think I was doing this because when creating the superuser I remembered entering an email and not a username (because django offers you a username without having to type it), and perhaps the usual convention of using emails for usernames.. Man I feel stupid haha.
我想我是这样做的,因为在创建超级用户时我记得输入电子邮件而不是用户名(因为django为您提供了用户名而无需输入用户名),也许是使用电子邮件进行用户名的通常惯例。我觉得很愚蠢哈哈。
#6
1
I had met the same situation just as you. And I found I switched the authentication backend to
我和你一样遇到了同样的情况。我发现我将身份验证后端切换为
someproject.backends.EmailCheckmodelBackend
someproject.backends.EmailCheckmodelBackend
And in the settings.py I had added a line:
在settings.py中我添加了一行:
AUTHENTICATION_BACKENDS = ('someproject.backends.EmailCheckModelBackend',)
AUTHENTICATION_BACKENDS =('someproject.backends.EmailCheckModelBackend',)
And the backend is like:
而后端就像:
class EmailCheckModelBackend(ModelBackend):
def authenticate(self, username = None, password = None, is_staff = None):
try:
user = User.objects.get(email = username)
if user.check_password(password):
if is_staff is not None:
if user.is_staff == is_staff:
return user
else:
return None
return user
except User.DoesNotExist:
return None
You will find actually the username is forced to be alternated by 'email'. So you have to login your page with email account. If like
实际上,您会发现用户名*通过“电子邮件”进行交替。因此,您必须使用电子邮件帐户登录您的页面。如果喜欢
Username: someone@somewhere.com
用户名:someone@somewhere.com
password: password
密码:密码
Then it works. Hope this helpful for everyone.
然后它工作。希望这对每个人都有帮助。
#7
0
I had the same problem and could not understand why I could not login because all the settings were correct. However, I traced it to Django offering me a superuser name containing an initial capital letter, but actually saving the name as completely lowercase!
我有同样的问题,无法理解为什么我无法登录,因为所有设置都是正确的。但是,我跟踪它给Django提供了一个包含首字母大写字母的超级用户名,但实际上将名称保存为完全小写!
I naturally used the superuser name with capitals (as offered by Django) and authentication failed. When inspecting the data tables to check 'is_staff' etc I spotted the error. I know I was not mistaken because I repeated the setup process a couple of times and noted the superuser credentials to be sure of details like case.
我自然地使用超级用户名和大写字母(由Django提供)并且身份验证失败。在检查数据表以检查'is_staff'等时,我发现了错误。我知道我没有弄错,因为我重复了几次设置过程并注意到超级用户凭据以确保像case一样的细节。
So, the moral is be careful when accepting the default name offered by Django! It lies!
因此,在接受Django提供的默认名称时,道德要谨慎!它在于!
#8
0
It's not that difficult to fix. First of all make sure to allow your default settings
修复起来并不困难。首先,请确保允许您的默认设置
(DEBUG=TRUE,ALLOWED_HOST=[ ])
in the settings file of your website folder.
在您的网站文件夹的设置文件中。
Get into your website folder (using the command prompt), and type the following command:
进入您的网站文件夹(使用命令提示符),然后键入以下命令:
$ python manage.py createsuperuser
name:
email:e.g fulluser@admin.com
password:
Go back into the browser and run the server. Set the username (not the email), alongside your password which you created earlier. It will surely work fine this time.
返回浏览器并运行服务器。设置用户名(而不是电子邮件)以及您之前创建的密码。这次肯定会工作正常。