python - Django 1.11 Pagination Markdown -
i tried paginate long string in django splitting using array did django-markdown-deux stopped working.
here how implemented it: models.py:
class post(models.model): content = models.textfield() def get_markdown(self): content = self.content markdown_text = markdown(content) return mark_safe(markdown_text)
views.py:
def post_detail(request, slug=none): #retrieve instance = get_object_or_404(post, slug=slug) #detect breaklines db , split paragraphs using tempinstance = instance.content paginatedinstance = tempinstance.split("\r\n\r\n") paginator = paginator(paginatedinstance, 5) #set how many paragraph show per page page = request.get.get('page', 1) try: paginated = paginator.page(page) except pagenotaninteger: paginated = paginator.page(1) except emptypage: paginated = paginator.page(paginator.num_pages) context = { "instance": instance, "paginated": paginated, #will use display story instead of instance (divided string paragraph) } return render(request, "post_detail.html", context)
post_detail.html:
this 1 works(without pagination):
{{ instance.get_markdown }}
this 1 works plain text if remove .get_markdown , won't display if put .get_markdown
{% paginatedtext in paginated %} {{ paginatedtext.get_markdown }} {% endfor %}
you paginatedtext
instance not have get_markdown
method defined. therefore, template fails silently when try call it. need use markdown
filter instead:
{% load markdown_deux_tags %} {% paginatedtext in paginated %} {{ paginatedtext|markdown }} {% endfor %}
Comments
Post a Comment