Search code examples
djangomarkdownpython-markdown

How to use multiple django-markdownx editors on the same page?


I have followed http://neutronx.github.io/django-markdownx/js/docs/markdownx.html#MarkdownX docs but can't get it done properly.

https://user-images.githubusercontent.com/27001046/41530962-7c225130-730f-11e8-9dd0-b915f08c3bc2.png

What is the correct way to setup two or more editors in the same page?


Solution

  • You don't have to set it up that way. MarkdownX is already initiated as your load {{form}} and {{form.media}}, so it has no meaning. Now, coming to your question. Using two editors on the same page in really straight forward.

    in your forms.py:

    from django import forms
    from markdownx.fields import MarkdownxFormField
    
    
    class FirstForm(forms.Form):
        yourfirstfield = MarkdownxFormField()
    
    
    class SecondForm(forms.Form):
        yoursecondfield = MarkdownxFormField()
    

    in your views.py:

    from django.shortcuts import render
    from .forms import FirstForm, SecondForm
    
    
    def form_view(request):
        context = {
            'first_form': FirstForm,
            'second_form': SecondForm
        }
        return render(request, 'form_template.html', context)
    

    in your form_template.html:

    <form>
        <p>{{first_form}}</p>
        <p>{{second_form}}</p>
    </form>
    

    I hope that helps!