【发布时间】:2017-05-30 09:39:10
【问题描述】:
我正在尝试在虚拟环境中的 ipython 中导入 Django 用户模型。我试过下面的代码
from django.contrib.auth.models import User
导致以下错误
AppRegistryNotReady: Apps aren't loaded yet.
然后从这个answer,我在shell里面设置并尝试了下面的代码。
from django.conf import settings
User = settings.AUTH_USER_MODEL
User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword')
这导致AttributeError: 'str' object has no attribute 'objects' . 如何在 ipython shell 中创建用户?我正在使用 Django 1.10.6,
ipython 6.0.0 和 djangorestframework 3.6.2
【问题讨论】:
-
只试试这个:User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword') -> 这对我有用。我建议你使用“shell_plus”
-
嗯,AUTH_USER_MODEL 是一个字符串。你为什么做这个?如果你通过
manage.py shell启动你的shell,你可以正常导入用户。
标签: python django django-rest-framework ipython python-3.4