Django-Sphinx RuntimeError:模型类models.Project没有声明

时间:2017-12-06 14:22:54

标签: django python-sphinx sphinx-apidoc

我正在尝试使用django项目的Sphinx生成html文档。在Windows cmd上执行make html时出现以下错误。 我的settings.py包含我构建的应用程序的条目,其中 models.py个文件属于。出于保密原因,我在这里称之为project_name。

INSTALLED_APPS = [
    'project_name.apps.project_nameAppConfig',
    'django.contrib.admin',
    'django.contrib.sites',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'import_export',
    'nested_admin',
    'report_builder',
    'rest_framework',
    'ajax_select',
]

错误追踪:

> C:\django_project\docs\source\models.rst:4: WARNING: autodoc: failed to
> import module 'models'; the following exception was raised: Traceback
> (most recent call last):   File
> "C:\Users\...\AppData\Local\Continuum\Anaconda3\lib\site-packages\sphinx\ext\autodoc.py",
> line 658, in import_object
>     __import__(self.modname)   File "C:\django_project\project_name\models.py", line 8, in <module>
>     class Project(models.Model):   File "C:\Users\...\AppData\Local\Continuum\Anaconda3\lib\site-packages\django\db\models\base.py",
> line 118, in __new__
>     "INSTALLED_APPS." % (module, name) RuntimeError: Model class models.Project doesn't declare an explicit app_label and isn't in an
> application in INSTALLED_APPS.

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

为我解决的问题是创建一个抽象类并从那里继承其他模型类,而不是直接从django.db模型类继承。在代码中有这样的东西:

function test() {           
    var e = document.getElementById("drop1");
    var strUser = e.options[e.selectedIndex].value;
    console.dir(strUser)
}

...

从这里得到了想法:Model class doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS