简体   繁体   中英

Autodoc Error when using Sphinx with Django

I am attempting to use sphinx autodoc in a Django project, but keep recieving the same error. 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:

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
======
.. automodule:: project.app.models
    :members:

However, whenever I run make html , I get the one line error:

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?

Changing my models.rst to look like:

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

fixed the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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