简体   繁体   English

使用带有 Django 的 Sphinx 时出现 Autodoc 错误

[英]Autodoc Error when using Sphinx with Django

I am attempting to use sphinx autodoc in a Django project, but keep recieving the same error.我正在尝试在 Django 项目中使用 sphinx autodoc,但仍然收到相同的错误。 My project is structured somewhat like so:我的项目结构有点像这样:

|project
|---app
|------models.py
|---docs
|------build
|------source
|---------conf.py
|etc

the top of my conf.py file looks like this:我的 conf.py 文件的顶部如下所示:

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

and my models.rst file looks like this:我的 models.rst 文件如下所示:

Models
======
.. automodule:: project.app.models
    :members:

However, whenever I run make html , I get the one line error:但是,每当我运行make html时,都会出现一行错误:

WARNING: autodoc: failed to import module 'app.models' from module 'project'; the following exception was raised:
No module named 'project.app'

Any suggestions?有什么建议么? Is this an issue with my sphinx configuration, or an issue with the django project?这是我的 sphinx 配置的问题,还是 django 项目的问题?

Changing my models.rst to look like:将我的 models.rst 更改为:

Models
======
.. automodule:: app.models
    :members:

fixed the issue.解决了这个问题。

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

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