简体   繁体   English

我使用django创建了一个博客,想知道我们是否需要将文章存储为html格式?

[英]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.

相关问题 html 如何在 django 中格式化我的博客文章? - How do I html format my blog post in django? 如何在 django2.1 中创建博客 mdel,这样我就不需要使用标签<p> ,<h3> ,还有,每次写博客都要加html标签 - How do I create a Blog mdel in django2.1, So that I don't need to use tags <p>,<h3>,<b> and all, Each time write blog I have to add html tags 如果有标签,为什么还需要标签? - Why do we need a <html> tag if we have <!DOCTYPE html>? 为什么我们需要JSF标签,如果我们有HTML标签 - Why do we need JSF tags , If we have HTML tags 使用Jsoup如何知道HTML页面中是否存在标签名称 - using Jsoup how we know whether a tag name exist in HTML page or not 我使用 javascript 在 HTML 中创建了一个表格 - I have created a table in HTML using javascript 如何在使用 HTML 和 CSS 制作的 web 中创建博客? 我需要 WordPress 吗? - How can I create a blog in a web that I make with HTML and CSS? Do I need WordPress? 我需要了解HTML和CSS才能使用jQuery Mobile吗? - Do I need to know HTML and CSS to use jQuery Mobile? 具有文章翻译功能的多语言博客的正确方法 - Correct way to have a multilangiage blog with article translation Django tinymce博客文章不格式化html - Django tinymce blog post don't format html
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM