Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/9999years/django-mdbook
Provides a simple MdBookView for Rust mdBooks, allowing them to exist within a Django site
https://github.com/9999years/django-mdbook
Last synced: 2 months ago
JSON representation
Provides a simple MdBookView for Rust mdBooks, allowing them to exist within a Django site
- Host: GitHub
- URL: https://github.com/9999years/django-mdbook
- Owner: 9999years
- License: mit
- Created: 2018-12-10T22:34:16.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2020-09-26T21:09:56.000Z (over 4 years ago)
- Last Synced: 2024-10-09T09:44:52.142Z (3 months ago)
- Language: Python
- Homepage:
- Size: 4.88 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
Provides a simple view for [mdBooks][mdbook], allowing them to exist within a
Django site. Note that because all requests are proxied through the
`MdBookView`, it will be a bit slower than using Apache or Nginx directly;
however, using a Django view allows fine-grained access control.Example use:
```python
import os.pathfrom django.contrib.auth.decorators import permission_required
from django.urls import path
from django.views.generic import RedirectViewfrom django_mdbook.views import MdBookView
directory = os.path.dirname(__file__)
def rel_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
"""
return os.path.join(directory, path)urlpatterns = [
path('doc/foo/',
RedirectView.as_view(url='index.html', permanent=True),
name='foo_doc_index'),
path('doc/foo/',
permission_required('doc.foo_documentation')(
# Note: book_root is the directory with book.toml, not the built directory
MdBookView.as_view(book_root=rel_to_abs('foo'))),
name='foo_docs')
]
```[mdbook]: https://github.com/rust-lang-nursery/mdBook