Sphinx book in django page, how to connect?

Hello there!

I’m trying to build an interactive book. Currently I’ve built a webpage in django with a user registration system. I’ve also built a basic book using sphinx and the pydata-sphinx-theme.

Now my problem is the following, when I ‘make’ the html files from my markdown pages in sphinx I get 10+ html files, each file containing (hardcoded) cross references to one of the other files. I can probably change the links to dynamic links by creating sphinx templates, but how do I import all these files in dango? Should I create a django view for every html page from sphinx ? Or is there possibly some jinja magic I could perform ? all html pages should live in one singe app, so there probably would be some smart way of doing this ?

Also, I have failed to find any tutorials on building sphinx into django, however there are numerous websites online who function by doing this (I suspect even the documentation page of django uses sphinx). Am I maybe using the wrong google search terms ?

I hope anyone can point me in the right direction here?

Currently my django views looks like this:

from django.shortcuts import render
#login_required
from django.contrib.auth.decorators import login_required

# Create your views here.
@login_required
def home(request):

    context = {
        'title': 'Book'
    }

    return render(request, 'book/home.html', context)

@login_required
def statics(request):

    context = {
        'title': 'Statics'
    }
    #How to import 10 chapters of sphinx html documents here ?
    return render(request, 'book/statics.html', context)

and one of the example sphinx files (a placeholder page) looks like this (please note the link list of links in the sidebar at the bottom of the html as well):

tutorial.html (39.3 KB)

Hi,
You need to create a separate view for each page and pass the context variables for each page to its corresponding view. Alternatively, you can create a single view that handles all the pages by dynamically generating the context variables based on the requested page.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.