This is awkward. But I can not understand the django-markdownx documentation on how to use the application. I completed the Getting Started guide, installed the application and the dependencies, added jquery and works in the admin backend. But the template does not display text = MarkdownxField()
as a properly formatted markdown, but as plain text.
I don’t understand this part ... and then include in the template the form required by the template using {{ form.media }}
:
<form method="POST" action="">{% csrf_token %} {{ form }} </form> {{ form.media }}
I tried to add this code immediately before the article tag in my template.
{% extends "base.html" %} {% block content %} <form method="POST" action="">{% csrf_token %} {{ form }} </form> {{ form.media }} <article> <h1>{{ article.title }}</h1> <p>{{ article.text }}</p> <div>{{ article.pub_date }} {{ article.category }} {{ article.tag }}</div> </article> {% endblock %}
But this does not correct.
What am I missing? I know this is trivial. But I have no experience in forms.
app/models.py
from django.db import models from django.urls import reverse from markdownx.models import MarkdownxField class Article(models.Model): title = models.CharField(max_length=250, verbose_name='title') text = MarkdownxField() pub_date = models.DateField(verbose_name='udgivelsesdato') category = models.ForeignKey(Category, verbose_name='kategori', null=True) tag = models.ForeignKey(Tag, verbose_name='mærke', null=True) def get_absolute_url(self): return reverse('article-detail', kwargs={'pk': self.pk}) def __str__(self): return self.title class Meta(): verbose_name = 'artikel' verbose_name_plural = 'artikler'
settings.py
INSTALLED_APPS = [ *** 'markdownx', 'articles', ] # Markdown extensions MARKDOWNX_MARKDOWN_EXTENSIONS = [ 'markdown.extensions.sane_lists', 'markdown.extensions.nl2br', 'markdown.extensions.extra', ]
urls.conf
from django.conf.urls import url, include from django.contrib import admin urlpatterns = [ url(r'^', include('articles.urls')), url(r'^markdownx/', include('markdownx.urls')), url(r'^admin/', admin.site.urls), ]
app/urls.py
from django.conf.urls import url from django.views.generic.dates import ArchiveIndexView from articles.models import Article from articles.views import ArticleDetailView, ArticleListView urlpatterns = [ url(r'^arkiv/$', ArchiveIndexView.as_view(model=Article, date_field="pub_date"), name="article_archive"), url(r'^$', ArticleListView.as_view(), name='article_list'), url(r'(?P<pk>\d+)/$', ArticleDetailView.as_view(), name='article_detail'), ]
app/templates/app/article_list.html
{% extends "base.html" %} {% block content %} <article> <h1>{{ article.title }}</h1> <p>{{ article.text }}</p> <div>{{ article.pub_date }}</div> </article> {% endblock %}
app/views.py
from django.views.generic import ListView, DetailView from articles.models import Article class ArticleListView(ListView): model = Article class ArticleDetailView(DetailView): model = Article