Django存储网站内容 [英] Django Storing Website Content

查看:83
本文介绍了Django存储网站内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对网络开发有点陌生,无法理解网站内容的存储方式。即使看过开源项目,我仍然感到困惑。

I'm a bit new to web development and am having trouble understanding how site content is stored. Even after looking at open source projects, I am still confused.

让我们说我有一个包含多个段落的网页,希望最终能够对其进行编辑Django管理页面。现在,我已经为页面设置了视图,但是不确定如何构造模型。

Lets say that I have a web page with multiple paragraphs that I am hoping to eventually be able to edit through the Django admin page. Now, I have the view set up for the page but I am unsure as how the models should be structured.

到目前为止,我有:

from django.db import models

class content(models.Model):
    name = models.CharField(max_length=30)
    last_updated = models.DateField(blank=True,null=True)
    content = models.TextField()

名称是我的段落将要谈论的内容,内容应该是该页面上的所有段落。我的问题:内容字段应该以HTML存储还是仅存储纯文本?如果是纯文本,将model.content字段嵌入到模板中时,如何添加HTML格式?

'name' is what my paragraphs will be talking about and 'content' should be all the paragraphs on that page. My question: Should the content field be stored in HTML or should I just store purely text? If it is pure text, how will I be able to add the HTML formatting when I embed the model.content field into my template? Wouldn't this be difficult see as I would need to parse the pure text to do so?

但是,如果我将HTML存储在内容字段中,会不会很困难,因为我需要解析纯文本吗?输入内容时必须使用HTML还是在管理页面中使用WYSIWYG编辑器?

However, if I store HTML in the content field, wouldn't I have to use HTML when entering content or use a WYSIWYG editor in the admin page?

谢谢您的帮助:)

推荐答案

在管理员中,您可以使用类似 TinyMCE 的WYSIWIG编辑器
将内容存储为HTML。渲染时-您可以执行 {{content | safe}}

In admin, you can use a WYSIWIG editor like TinyMCE This would store the content as HTML. While rendering - you can do {{content|safe}}.

查看 django-flatpages 。它正是您要拍摄的东西。

Look into django-flatpages. it does exactly what you are shooting for.

这篇关于Django存储网站内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆