简体   繁体   English

与Django 1.4的Sphinx autodoc

[英]Sphinx autodoc with Django 1.4

I'm having issues building the module autodocs for a Django 1.4.1 project. 我在为Django 1.4.1项目构建模块autodocs时遇到问题。 make html seems to be failing to read my docstrings because it's running into trouble importing my settings. make html似乎无法读取我的文档字符串,因为它在导入我的设置时遇到了麻烦。 All of the online guides I've seen suggest using 我见过的所有在线指南都建议使用

import settings
from django.core.management import setup_environ
setup_environ(settings)

but this is deprecated in 1.4, and the settings.configure() method doesn't seem appropriate. 但这在1.4中已弃用,而settings.configure()方法似乎不合适。 I haven't found nearly as much information for how to make things work in 1.4. 我没有找到关于如何在1.4中使用工作的信息。 I tried setting DJANGO_SETTINGS , but no luck. 我试过设置DJANGO_SETTINGS ,但没有运气。 Any suggestions? 有什么建议么?

The problem seems to be that I incorrectly set a DJANGO_SETTINGS environment variable, when I needed to set DJANGO_SETTINGS_MODULE . 问题似乎是当我需要设置DJANGO_SETTINGS_MODULE时,我错误地设置了一个DJANGO_SETTINGS环境变量。

So, to be clear, because this info is not particularly well documented, there are two equivalent ways to setting up autodocs with Django 1.4+: 所以,要清楚,因为这些信息没有特别详细记录,有两种方法可以使用Django 1.4+设置autodoc:

  1. Set environment variables before running make html : 在运行make html之前设置环境变量:

     export PYTHONPATH=<path to root of source> export DJANGO_SETTINGS_MODULE=myproject.settings 
  2. Do the equivalent in conf.py : conf.py执行等效conf.py

     sys.path.append('<path to root of source>') os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings' 

I prefer the latter because I can set it in the configuration and the docs will build in any deployment. 我更喜欢后者,因为我可以在配置中设置它,文档将在任何部署中构建。

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

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