sphinx显示的是django基本视图,而不是我自己的views.py

时间:2018-04-22 04:13:30

标签: python django python-sphinx

在Django站点上使用Sphinx时显示的视图是: enter image description here

我的views.py的开头是:

import os
from django.shortcuts import render, redirect 
from django.urls import reverse 
from django.http import HttpResponse, HttpResponseRedirect 
from django.utils import timezone
from . forms import PlayForm, RollForm, checkBoard, BossForm
from random import randint 
from . templatetags.playExtras import translateDice 
from .models import Board, Winner, Boss

def getFirstFolder(req):
    """ return the string between first two / - this is a hack, find out how to do it with the object """
    r = req.split("'")
    loc = r[1].find('/',1)
    x = r[1][1:loc]
    return(x)

def loadBoard(request,context,location=''):
    ''' Load the board from the database into context. Add a hyperlink for available squares.

    :param context: context for template
    :type context: dictionary

    :param location: Comma seperated string of available locations or empty string so no links included.
    :type location: str

    :return: 'not on the board' or 'all taken' or comma seperated string of location options such as 'A0,B0'
    :rtype: str    
    '''
    req = request.__str__()

如果我没有显示Python所在的Sphinx,我就会收到错误。我在Sphinx的conf.py中添加的路径是:

ourPaths = [
    '/game/',
    '/game/game',
    '/game/play',
    '/game/play/templatetags'
    ]
for p in ourPaths:
    abspath = os.path.abspath('.')  + p
    print('path..................',abspath)
    sys.path.insert(0, abspath)
# Need to point to where the Django is on this system. FIND OUT HOW TO MAKE THIS RELATIVE
sys.path.insert(0,'/home/ajp/Downloads/env/lib/python3.5/site-packages')
sys.path.insert(0,'/home/ajp/Downloads/env/lib/python3.5/site-packages/django')

我正在使用的views.rst文件:

views module
==============

.. automodule:: views
    :members:
    :undoc-members:
    :show-inheritance:

我搜索了几天,但我担心我不知道正确的术语搜索找到答案。

我可以使用其他代码显示,但我也需要在手册中查看我的代码。

感谢您提供任何帮助。

2 个答案:

答案 0 :(得分:0)

Tony Flury在django-users@googlegroups.com上指出了其他探索。我最终发现Jens Hedegaard Nielsen在({3}}给出了答案(间接)。在那里他指出

autodoc_mock_imports = [“django”]

在Sphinx文档https://github.com/sphinx-doc/sphinx/issues/4182

答案 1 :(得分:0)

在某些情况下,autodoc_mock_imports解决方案可以工作,但是我的项目越大,我就越需要“陪审团”来保持工作,直到我最终放弃并等待再次尝试。本周,Doris Wang和我尝试在我们用于Django的virtualenv中构建狮身人面像,并且效果很好。在我使用的Debian系统上,我使用了:

python -m pip install sphinx

在环境中安装sphinx。