2

I am new using markdown. I tried to use the show_preview = False to implement preview using jQuery instead.

class PostForm(forms.ModelForm):
    content = forms.CharField(widget=PagedownWidget(show_preview=False)) 
    publish = forms.DateField(widget = forms.SelectDateWidget)
    class Meta:
        model = Post
        fields = [
            "title",
            "content",
            "image",
            "draft",
            "publish",
        ]

unfortunately, it throws an error:

line 9, in PostForm
content = forms.CharField(widget=PagedownWidget(show_preview=False))
TypeError: __init__() got an unexpected keyword argument 'show_preview'

I did look into the markdown files and could not find show_preview using except here:

4          <textarea {{ attrs|safe }}>{{ body }}</textarea>
5      </div>
6      {% if show_preview %}
7      <p class="wmd-preview-title">
8          <small>HTML Preview:</small>

I am running:

Django==2.2.6
django-markdown-deux==1.0.5
django-pagedown==2.0.3
EarlyCoder
  • 1,213
  • 2
  • 18
  • 42

1 Answers1

1

Are you following a guide? Django-pagedown widget used to take a number of arguments (including show_preview). Use version 1.0.6 if you want to do that. v1.0.6 is still compatible with django2.2.x.

Since v2.0.0 it is better to subclass the widget and point it to the template / css to define the preview box, see the docs for that:

Github (see the readme)

Example app with form

You can stop the preview showing by overwriting the CSS. eg, add the following to your .css file in the static folder (and ensure it is being imported into your template). Or just stick it in a style tag at the top of your template.

.wmd-preview{
    display: none;
}
Yobmod
  • 395
  • 3
  • 5
  • 18
  • Yes, I am following a seemingly dated guide. So, is there a documentation link I can use to show how to extend the widget and point it to the template? – EarlyCoder Oct 21 '19 at 17:18
  • added links. I think you can just remove the show_preview=True (it shows by default). So you don't need to subclass, just follow the example. – Yobmod Oct 21 '19 at 17:22
  • I ended up doing that, but the preview does show up if you do not get rid of it somehow. So, any idea how to remove the preview? – EarlyCoder Oct 21 '19 at 17:41
  • ah, you want the preview gone? Overwrite the CSS is the quickes way. Added to answer – Yobmod Oct 22 '19 at 07:48