提供使用mdbook创建的图书的服务和更新视图
django-mdbook的Python项目详细描述
为mdBooks提供了一个简单的视图,允许它们存在于
Django遗址请注意,因为所有请求都是通过
MdBookView
,比直接使用apache或nginx要慢一点;
但是,使用django视图允许细粒度的访问控制。
示例使用:
importos.pathfromdjango.contrib.auth.decoratorsimportpermission_requiredfromdjango.urlsimportpathfromdjango.views.genericimportRedirectViewfromdjango_mdbook.viewsimportMdBookViewdirectory=os.path.dirname(__file__)defrel_to_abs(path:str)->str:""" Given a path relative to this file, give its absolute name :param path: a relative path to resolve :return: an absolute path """returnos.path.join(directory,path)urlpatterns=[path('doc/foo/',RedirectView.as_view(url='index.html',permanent=True),name='foo_doc_index'),path('doc/foo/<path:path>',permission_required('doc.foo_documentation')(# Note: book_root is the directory with book.toml, not the built directoryMdBookView.as_view(book_root=rel_to_abs('foo'))),name='foo_docs')]