django_md_editor

django_md_editor package helps integrate editor.md with Django.


Keywords
editor.md, django, editor, markdown, md
License
MIT
Install
pip install django_md_editor==0.1.61

Documentation

Join and Contact us

Join and Contact us on Discord

What is Django-md-editor?

Django-md-editor package (django app) helps integrate editor.md with Django.

How to I Install This App?

You can install using pip.

Perform the following steps in sequence.

  • pip install django_md_editor

  • pip install django_md_editor -U

  • Add django_md_editor to INST ALLED_APPS in settings.py like this below. INSTALLED_APPS.append("django_md_editor")

  • and you can write your editor config setting. you can see the default configuration settings below.

DEFAULT_CONFIG = {
    "width": "100%",
    "heigth": "500px",
    "toolbar": ["undo", "redo", "|",
                "bold", "del", "italic", "quote", "ucwords", "uppercase", "lowercase", "|",
                "h1", "h2", "h3", "h5", "h6", "|",
                "list-ul", "list-ol", "hr", "|",
                "link", "reference-link", "image", "code", "preformatted-text", "code-block", "table", "datetime",
                "emoji", "html-entities", "pagebreak", "goto-line", "|",
                "help", "info",
                "||", "preview", "watch", "fullscreen"],
    "upload_image_formats": ["jpg", "JPG", "jpeg", "JPEG", "gif", "GIF", "png",
                             "PNG", "bmp", "BMP", "webp", "WEBP"],
    "image_floder": "editor",
    "theme": "default",
    "preview_theme": "default",
    "editor_theme": "default",
    "html_decode": "html, iframe",
    "at_link_base": "/@",
    "image_upload_url":"/media/uploads/",
    "toolbar_autofixed": False,
    "search_replace": False,
    "emoji": False,
    "tex": True,
    "image_upload": False,
    "flow_chart": True,
    "sequence": True,
    "at_link": False,
    "email_link":False,
}

How to Use This App?

Example;

/models.py

from django_md_editor.models import EditorMdField

class Page(models.Model):
    content = EditorMdField()

/forms.py

from django.forms import ModelForm
from myapp.models import Content

class ContentForm(ModelForm):
    class Meta:
        model = Content
        fields = ["content"]

/views.py

# form
from cooggerapp.forms import ContentForm
from django.views import View

class Create(View):

    def get(self, request, *args, **kwargs):
        form = ContentForm()
        return render(request, "index.html", {"form": form})

    def post(self, request, *args, **kwargs):
        form = ContentForm(data=request.POST)
        if form.is_valid():
            form = form.save()
            return HttpResponseRedirect("/")

templates/index.html

<form action="{% url 'post' %}">
  {% csrf_token %}
  {{ form }}
  {{ form.media }}
  <input type="submit" value="Save">
</form>

How to convert markdown to html in my template?

For example ; If you want to show the shared content on the detail page?

  • install djmd_tags in your template like this below {% load django_md_editor %}
  • and use {{ markdown_text|markdown_to_html:"id"|safe }}