简体   繁体   English

带有 Django 错误的 Autodoc Sphinx

[英]Autodoc Sphinx with django error

I get an error when I try to make html with autodoc.当我尝试使用 autodoc 制作 html 时出现错误。

Here is my project structure :这是我的项目结构:

projet
--- app1
------ models.py
------ views.py
--- app2
--- app3
docs
--- modules
------ models.rst
--- conf.py
--- index.rst
__init__.py
manage.py

My conf.py我的 conf.py

import os
import sys

sys.path.insert(0, os.path.abspath('..'))
from django.conf import settings
settings.configure()

import django
django.setup()

# -- General configuration 

extensions = ['sphinx.ext.autodoc',
'sphinx.ext.coverage']

And my model.rst还有我的model.rst

Models
======
.. automodule:: projet.app1.models
    :members:
    :undoc-members:

And I het this error :我遇到了这个错误:

D:\Agrome\Agrome bitbucket\agrome-backend\docs\modules\models.rst:3: WARNING: autodoc: failed to import module u'agrome.boxes.models'; the following exception was raised:
    Traceback (most recent call last):
        File "c:\python27\lib\site-packages\sphinx\ext\autodoc.py", line 547, in import_object
        __import__(self.modname)
        File "D:\Agrome\Agrome bitbucket\agrome-backend\agrome\boxes\models.py", line 5, in <module>
        from django.contrib.auth.models import User
        File "c:\python27\lib\site-packages\django\contrib\auth\models.py", line 6, in <module>
        from django.contrib.contenttypes.models import ContentType
        File "c:\python27\lib\site-packages\django\contrib\contenttypes\models.py", line 161, in <module>
        class ContentType(models.Model):
        File "c:\python27\lib\site-packages\django\db\models\base.py", line 102, in __new__
        "INSTALLED_APPS." % (module, name)
RuntimeError: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

If I type .. automodule:: projet.app1 (whitout .models), it works but the doc is empty.如果我输入 .. automodule:: projet.app1 (whitout .models),它可以工作,但文档是空的。

Do you have any idea ?你有什么主意吗 ?

Thanks a lot非常感谢

尝试删除/注释掉 conf.py 中的settings.configure()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM