python - 使用 django-users2 时无法导入 users.form

标签 python django linux

这是我的导入

from users.forms import RegistrationForm

如果我像这样导入,将引发异常:

django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

在设置中设置 secure_key 后,我尝试使用 django.setup()

但是会引发另一个异常:

RuntimeError: Model class Article.models.Article_model doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

但是我已经把 Article 放在 INSTALLED_APPS 里了。 不知道为什么

这里是引发异常的地方 enter image description here

enter image description here

最佳答案

您可以尝试升级到 Django 1.11 - 它允许您在运行时使用 get_user_model() (release notes)。即使这不能解决问题,升级也是个好主意——Django 2.0 即将发布时,Django 1.10 将不受支持。

请注意,django.setup() 用于独立脚本。你不应该在你的设置中使用它。

关于python - 使用 django-users2 时无法导入 users.form,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47413839/

相关文章:

linux - 如果 nginx 配置正在运行或停止,如何重新加载它?

python - Pandas 错误 : 'DataFrame' object has no attribute 'loc'

python - 在 numpy 中计算联合 pmf 的条件概率,太慢了。有想法吗? (python-numpy)

python - 如何在 Django/Python 中加入 ManyToMany 查询集

python - 扩展形式悄无声息地失败了

代理后面的 Java 应用程序在 Linux 中使用 http_proxy 变量

sql-server - SQL 服务器 ODBC 驱动程序 linux 用户名 ''

python - python 中的嵌套 if else 语句

python - 将带有 rbf 内核的 sklearn SVC 移植到 java

python - 如何在 Django 2.1 中使用多种形式?