Skip to main content

A simple Django app to generate pages from files.

Project description

Mdpages is a simple Django app to generate pages from Markdown files.

Pages also can have a Table of Content automatically generated based on headings.

Quick start

Supposing you want to create an About page, having the markdown file at /pages/content/about.md.

  1. Add “mdpages” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [
        ...
        'mdpages',
]
  1. Set the location of the directory that will contain the Markdown files in settings with MDPAGES_CONTENT_DIR:
MDPAGES_CONTENT_DIR = '{}/pages/content/'.format(BASE_DIR)
  1. Add the template that will contain the Markdown generated content, you will have two variables available: body and toc (for the table of contents), for example create a template /templates/mdpages/page.html with contents like:
{% extends "base.html" %}

{% block title %}{{title}}{%endblock%}
{% block description %}{{description}}{%endblock%}

{% block content %}
<div class="container">
     {{ toc|safe }}
     <hr>
     {{ body|safe }}
</div>
{% endblock %}

And add the template path to settings MDPAGES_TEMPLATE_NAME:

MDPAGES_TEMPLATE_NAME = 'mdpages/page.html'
  1. Create a view using staticages.views.MdPageView specifying the name of the Markdown file md_file and the template_name:
from mdpages.views import MdPageView

class AboutView(MdPageView):
        md_file = 'language-learning.md'

        # any kind of extra content used in your template
        extra_context = {
                'title': 'About page',
                'description': 'This is the about page of the site.'
        }
  1. Use it in your urls.py:
from .views import AboutView

urlpatterns = [
        path('about', AboutView.as_view()),
]

Project details


Release history Release notifications

This version
History Node

0.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django_mdpages-0.2-py3-none-any.whl (4.2 kB) Copy SHA256 hash SHA256 Wheel py3
django-mdpages-0.2.tar.gz (3.8 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page