Django:Python Shell中的访问管理员用户 [英] Django: Access Admin User in Python Shell

查看:149
本文介绍了Django:Python Shell中的访问管理员用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Django Userena,但是当尝试登录django管理屏幕时,userena引起了大惊小怪:Profile matching query does not exist.

I am using Django Userena, but when trying to login to the django admin screen userena is creating a fuss: Profile matching query does not exist.

如何使用Shell为管理员用户创建配置文件?这是我的个人资料模型,但我不知道如何访问管理员用户的密钥以为其创建个人资料对象:

How can I create a profile for the admin user using the shell? Here is my Profile model, but I don't know how to access the key for the admin user to create a Profile object for it:

class Profile(UserenaBaseProfile, FacebookProfileModel):
    user = models.OneToOneField(User,
                                unique=True,
                                verbose_name=('user'),
                                related_name='my_profile')
    website = models.URLField(null=True, blank=True)

我知道这可能很简单,但是Google到目前为止使我失败了...感谢您的想法!

I know this is probably pretty simple, but google has failed me so far... Thanks for your ideas!

PS.我曾经能够正常登录到管理屏幕,但是现在发生了一些变化,并且出现了Profile matching query does not exist错误(我也没有更改代码)..为什么现在无法登录的任何想法也表示赞赏.谢谢!

PS. I used to be able to login to my admin screen without issue, but something has changed now and I am getting the Profile matching query does not exist error (I didn't change the code, either).. Any ideas why I can't login now are also appreciated. Thanks!

推荐答案

您可以执行以下操作:

$ ./manage.py shell
> from django.contrib.auth.models import User
> from <profile_package>.models import Profile
> user = User.objects.get(username='<admin_user_name>')
> profile = Profile(user=user)
> profile.save()

这篇关于Django:Python Shell中的访问管理员用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆