Django-markdown: How to disable loading image when render article briefing
I am a beginer of web development and I have had some python exprience while this is my first try on django (Django==3.2
) .
I have managed to store markdown article by using Markdown==3.3.7
, the everything looks like:
# models.py
class ArticlePost(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
title = models.CharField(max_length=64)
body = models.TextField()
# views.py
def article_create(request):
if request.method == "POST":
article_post_form = ArticlePostForm(data=request.POST)
if article_post_form.is_valid():
new = article_post_form.save(commit=False)
new.author = User.objects.get(id=1)
new.body = markdown.markdown(
new.body,
extensions=[
'markdown.extensions.extra',
])
new.save()
return redirect("article:article_list")
# else:
# Shell test:
>>> print(article.body)
<p><a href="https://img.com/"><img alt="test.png" src="https://xxxx" /></a></p>
>>> type(article.body)
<class 'str'>
at first it looks like:
so I use CSS display:none
, the img doesn't render just as expecting
But I happened to find that display:none
doesn't prevent browser to load image:
a practical way is when calling article_create()
"sed" out img tag and dump a copy which is only for the usage of rendering the brief
but to me, I prefer some way that I can remain current article.body
content, then add something in html or css, so that I can make the brief
brief(cuz it render without loading img).
thx in advance!