本文介绍了狮身人面像自动模式:如何在同一模块中引用类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用狮身人面像扩展程序,特别是automodule指令自动生成django应用程序的文档我正在处理。问题是我想在模块中创建对不同类的内部引用,而不必在项目中的每个类/函数上使用自动类和自动功能。对于像这样的源文件:

 #source_code.py 
class A:
docs对于A

通过

类B:
文档B与
:ref:`内部引用A< XXXX-some-reference-to-A-XXXX>`

pass

我希望能够使用这样的狮身人面像文档:

  .. automodule:source_code 

可以使用什么引用XXXX-some-reference-to-A-XXXX?有没有办法完成这个?感谢您的帮助。

解决方案

您可以参考这样的课程:


$ b对于B,参考:class:`.A`
pass
pre> $ b

Sphinx将智能地尝试并弄清楚您正在引用的内容。如果有多个类别,名称为 A ,您可能会收到警告,但应该在当前模块中选择一个。


I am trying to use the sphinx autodoc extension and specifically the automodule directive to automatically generate documentation for django app I am working on. The problem is that I want to create internal references to different classes within the module, without having to use autoclass and autofunction on every single class/function within the project. For a source file like this:

# source_code.py
class A:
    """docs for A
    """
    pass

class B:
    """docs for B with 
    :ref:`internal reference to A <XXXX-some-reference-to-A-XXXX>`
    """
    pass

I would like to be able to have a sphinx documentation file like this:

.. automodule: source_code

What reference can I use for XXXX-some-reference-to-A-XXXX? Is there an easy way to accomplish this? Thanks in advance for your help.

解决方案

You can reference a class like this:

class B(object):
    """docs for B with reference to :class:`.A`"""
    pass

Sphinx will intelligently try and figure out what you're referencing. If there are multiple classes with the name A, you might get a warning, but it should pick up the one in the current module.

这篇关于狮身人面像自动模式:如何在同一模块中引用类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 13:51