Example

Model

1
2
3
4
from markdownx.models import MarkdownxField

class MyModel(models.Model):
    myfield = MarkdownxField()

... and then, include a form’s required media in the template using {{ form.media }}:

<form method="POST" action="">{% csrf_token %}
    {{ form }}
</form>

{{ form.media }}

Form

1
2
3
4
from markdownx.fields import MarkdownxFormField

class MyForm(forms.Form):
    myfield = MarkdownxFormField()

... and then, include a form’s required media in the template using {{ form.media }}:

<form method="POST" action="">{% csrf_token %}
    {{ form }}
</form>

{{ form.media }}

Django Admin

When using included MarkdowxModel class in your models, just use MarkdownxModelAdmin in your admin.py as follows:

1
2
3
4
5
6
from django.contrib import admin
from markdownx.admin import MarkdownxModelAdmin
from .models import MyModel


admin.site.register(MyModel, MarkdownxModelAdmin)

Field customization

We have ensured that MarkdownX is fully extensible and provides a high degree of flexibility in development.

There are times that you may wish to Markdownify a different type field, or utilize your own customized model. To accommodate this, we have provided the tools to apply MarkdownX infrastructure to other fields through Widgets.

For instance, to apply MarkdownX to TextField instances in your Django Admins, you can override the default widget in the Admins module in admin.py of your Django App as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
from django.db import models
from django.contrib import admin

from markdownx.widgets import AdminMarkdownxWidget

from .models import MyModel


class MyModelAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.TextField: {'widget': AdminMarkdownxWidget},
    }


admin.site.register(MyModel, MyModelAdmin)