Sphinx autodoc与Django 1.4 [英] Sphinx autodoc with Django 1.4

查看:223
本文介绍了Sphinx autodoc与Django 1.4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在构建Django 1.4.1项目的模块autodoc时遇到问题。 make html 似乎无法读取我的文档,因为导入我的设置遇到麻烦。我看到的所有在线指南都建议使用

I'm having issues building the module autodocs for a Django 1.4.1 project. make html seems to be failing to read my docstrings because it's running into trouble importing my settings. All of the online guides I've seen suggest using

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

但在1.4中已经弃用,而$ code > settings.configure()方法似乎不合适。我在1.4中没有发现几乎有关如何使事情发挥作用的信息。我尝试设置 DJANGO_SETTINGS ,但没有运气。任何建议?

but this is deprecated in 1.4, and the settings.configure() method doesn't seem appropriate. I haven't found nearly as much information for how to make things work in 1.4. I tried setting DJANGO_SETTINGS, but no luck. Any suggestions?

推荐答案

问题似乎是我错误地设置了一个 DJANGO_SETTINGS 环境变量,当我需要设置 DJANGO_SETTINGS_MODULE

The problem seems to be that I incorrectly set a DJANGO_SETTINGS environment variable, when I needed to set DJANGO_SETTINGS_MODULE.

所以,要清楚,因为这个信息是没有特别详细的记录,有两种等效的方法来设置Django 1.4 +的自动对焦:

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+:


  1. 在运行 make html

export PYTHONPATH=<path to root of source>
export DJANGO_SETTINGS_MODULE=myproject.settings


  • conf.py

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




    1. 我更喜欢后者,因为我可以在配置中进行设置,文档将在任何部署中构建。

    I prefer the latter because I can set it in the configuration and the docs will build in any deployment.

    这篇关于Sphinx autodoc与Django 1.4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆