django - 导入错误 : cannot import name update_all_contenttypes

标签 django django-1.8

我最近升级到 Django 1.8。在以前的 Django 版本中,以下导入没问题:

from django.contrib.contenttypes.management import update_all_contenttypes

但是update_all_contenttypes似乎已在 Django 1.8 中被悄悄删除(它在 1.7.7 中存在)。我在 1.8 release notes 中没有看到任何内容关于它的删除......有谁知道该功能的现代替代品是什么?

最佳答案

目前尚不清楚为什么该功能在 1.8 中被删除,但现代替代品似乎只是重新发明了那个轮子:

from django.apps import apps
from django.contrib.contenttypes.management import update_contenttypes

def update_all_contenttypes(**kwargs):
    for app_config in apps.get_app_configs():
        update_contenttypes(app_config, **kwargs)

关于django - 导入错误 : cannot import name update_all_contenttypes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29550102/

相关文章:

Django 表单字段未显示

django - 如何从对 django 的前端响应中捕获错误和异常数据以添加更多上下文

Django - 找不到静态文件

python - 不在 ListView 中时,django rest framework 添加字段

django - 使用自定义管理站点自动注册 Django 身份验证模型

django - 多个 Django 应用程序,共享身份验证

python - 在 Django 中使用 refresh_from_db 的正确方法是什么?

python - Django 1.8 错误的 PyDev 错误

Django + PostgreSQL : Fill missing dates in a range

python - POST 请求在使用 Plivo 的 Django IVR 中不起作用