Hi i am practicing Django and Python
And i encounter with parse HTML problem, i saved some html through admin page, and i tried to render,but it rendered as string!
This is my part of template
description <- columns is my problem
other columns are rendered well
{% block content %}
<div class="article-detail">
<div class="article">
<img src="{{ article.thumb.url }}" />
<h2>{{ article.title }}</h2>
<p>{{ article.date }}</p>
<div>
{{ article.description }}
</div>
</div>
</div>
{% endblock %}
And this is my model
from tinymce import HTMLField
class Article(models.Model):
title = models.CharField(max_length=100)
slug = models.SlugField()
body = models.TextField()
description = HTMLField('Content', blank=True)
body = models.TextField()
date = models.DateTimeField(auto_now_add=True)
thumb = models.ImageField(default='default.png', blank=True)
...
This part of my view
def article_detail(request, slug):
article = Article.objects.get(slug=slug)
return render(request, 'articles/article_detail.html', {'article': article})
I tried to use javascript
{% block content %}
<div class="article-detail">
<div class="article">
<img src="{{ article.thumb.url }}" />
<h2>{{ article.title }}</h2>
<p>{{ article.date }}</p>
</div>
</div>
<script>
var article = "<div>{{ article.description }}</div>"
console.log(article);
document.write(article);
</script>
{% endblock %}
I hoped this work but
But i got JS syntax Error
console dosen't show anything
Why?
If it transformed to string, it should work....
And what is best way to render it ?
And i am sorry for my poor English