[英]I have created a blog using django and wanted to know whether do we need to store the article as in html format?
I have created a simple blog which consists below model. 我创建了一个简单的博客,其中包含以下模型。
class Blog(models.Model):
article_content = models.TextField()
----
something more here.
---
views.py views.py
def article_detail(request,pk=article_id):
articles = Blog.objects.get(pk=article_id)
----
return render (request,'article.html',{'article':articles})
template 模板
{{article.article_content}}
But this will simply display the whole content. 但这只会显示整个内容。 how to make the different css property to sub-headings and to links.
如何使不同的CSS属性成为子标题和链接。 I want to display something like below.
我想显示以下内容。 Pls help.
请帮助。
my question is when i will create the queryset , it will return whole article page. 我的问题是何时创建queryset,它将返回整个文章页面。 But there will be different sub-heading also and links.
但是也会有不同的子标题和链接。 do i make them store as html format?
我如何将它们存储为html格式?
I want the article something like this. 我想要这篇文章。
Heading 标题
contents 内容
sub-heading 副标题
sub-heading contents and some images . 小标题内容和一些图片。
Usually the heading is the title field of a blog. 通常,标题是博客的标题字段。 So you could create that as a separate model field.
因此,您可以将其创建为单独的模型字段。
But assuming it is truly in the content portion that you need the output rendered with markup, first the data needs to be stored with markup. 但是,假设您确实需要在内容部分中使用标记呈现输出,那么首先需要使用标记存储数据。 For this, consider who will be inputting the content data.
为此,请考虑谁将输入内容数据。 You should do this anyway, but especially if it's non-admin users you need to sanitize the input data before it's saved.
无论如何,您都应该这样做,但是特别是如果它是非管理员用户,则需要在保存输入数据之前对其进行清理。 Also consider using something like django-tinymice to make the content input user friendly.
还可以考虑使用django-tinymice之类的东西来使内容输入变得用户友好。
For the output, you will then want to allow html tags in the template using the "safe" filter or {% autoescape_off %}. 对于输出,您将希望使用“安全”过滤器或{%autoescape_off%}允许模板中的html标签。 Consider using a whitelist based sanitizing library such as bleach to guard against the may ways you can open yourself up to risk when rendering user input like this.
考虑使用基于白名单的消毒库(例如漂白剂)来防止您在呈现这样的用户输入时可能冒着风险的可能方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.