sphinx is showing the django base views instead of my own views.py

51 views
Skip to first unread message

Anthony Petrillo

unread,
May 4, 2018, 11:25:20 AM5/4/18
to Django users

The view being shown when using Sphinx on a Django site is: 


The beginning of my views.py is:


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__()


I was getting errors if I didn't show Sphinx where the Python was located. The path additions I made in the Sphinx's conf.py are:

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')


The views.rst file I'm using: 

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

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

I searched for days but I'm afraid I do not know the right terms search for to find the answer. I posted on stackoverflow for a couple weeks and no responses at all. 

I'm okay with the other code showing up, but I'd need to see my code in the manual as well.

Thank you for any help you can give. 

Anthony Flury

unread,
May 5, 2018, 6:43:50 PM5/5/18
to django...@googlegroups.com
Can you be clear what you are trying to do ?

Did you want your Sphinx Page to display an alternative Django
documentation - i.e. a module reference for Django ?

Or did you want your Sphinx Page to document your app  - if so the issue
is that your rst just calls for the views module - and that is the one
in sys.path (i.e. Django); if you want the views.py from your app - your
rst has to reference the full dotted path to the views module :

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

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





On 04/05/18 16:09, Anthony Petrillo wrote:
>
> The view being shown when using Sphinx on a Django site is:
>
> <https://lh3.googleusercontent.com/-IyVWh5gFHgg/Wux2UtHMdTI/AAAAAAAAXAM/ttdoOJAmaa0PZZSuKxsoEs27EJi45tssACLcBGAs/s1600/HMzGQ.png>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e53d3f68-b008-4d4a-a9bd-74d1af57337c%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/e53d3f68-b008-4d4a-a9bd-74d1af57337c%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--
--
Anthony Flury
email : *Anthon...@btinternet.com*
Twitter : *@TonyFlury <https://twitter.com/TonyFlury/>*

Anthony Petrillo

unread,
May 5, 2018, 8:45:48 PM5/5/18
to Django users
Thank you Tony. It is the second option, documenting my code. 

I changed my rst to (note the site name was changed from game to rival5):

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

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

I have the following added to the path in conf.py:

ourPaths = [
    '/rival5/',
    '/rival5/rival5',
    '/rival5/play',
    '/rival5/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')

I have __init__.py in all the directories. 

I'm getting this error:

WARNING: /home/ajp/ownCloud/CEO/SC/Customers/Rival5/source/rival5/play/views.rst:4: (WARNING/2) autodoc: failed to import module 'rival5.play.views'; the following exception was raised:
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/sphinx/ext/autodoc.py", line 658, in import_object
    __import__(self.modname)
ImportError: No module named 'rival5.play'

I searched and the recommendation is to be sure to include the path to the file in conf.py which I've already done, unless I'm making a mistake. I have other code that is not part of the django naming scheme and it works fine. 

I'm hoping my mistake is obvious to you. Thanks so much for your time. 

Anthony Petrillo

unread,
May 8, 2018, 10:36:50 PM5/8/18
to Django users
Solved.

Thank you again Tony for pointing me in the right direction.

Jens Hedegaard Nielsen gave the answer (indirectly) at https://github.com/sphinx-doc/sphinx/issues/4182. There he pointed to 

autodoc_mock_imports = ["django"


Anthony


On Friday, May 4, 2018 at 11:25:20 AM UTC-4, Anthony Petrillo wrote:
Reply all
Reply to author
Forward
0 new messages