文章添加页(富文本编辑器的使用),
文章添加页(富文本编辑器的使用),
1.文章添加页url开设
2.添加文章页面已经富文本编辑器的使用
富文本编辑器kindeditor只要到官网下载下来,放入static文件夹就行,如何在html的script处添加对应固定代码
{% extends 'backend/base.html' %}
{% block article %}
<h3>添加随笔</h3>
<form action="" method="post">
<p>标题</p>
<div>
<input type="text" class="form-control" name="title">
</div>
<p>内容</p>
<div>
<textarea name="content" id="editor_id" cols="30" rows="10"></textarea>
</div>
<p>分类</p>
<div>
{% for category in category_list %}
<input type="radio" value="{{ category.pk }}" name="category">{{ category.name }}
{% endfor %}
</div>
<p>标签</p>
<div>
{% for tag in tag_list %}
<input type="checkbox" value="{{ tag.pk }}" name="tag">{{ tag.name }}
{% endfor %}
</div>
<br>
<input type="submit" class="btn-danger btn">
</form>
{% endblock %}
{% block js %}
<script charset="utf-8" src="/static/kindeditor-4.1.11-zh-CN/kindeditor/kindeditor-all-min.js"></script>
<script>
KindEditor.ready(function (K) {
window.editor = K.create('#editor_id',
{
width: '100%',
height:'600px',
resizeType:1,
});
});
</script>
{% endblock %}
3.后端需要传入到前端的数据
4.添加文章向后端发送请求
@login_required
def add_article(request):
category_list = models.Category.objects.filter(blog=request.user.blog)
tag_list = models.Tag.objects.filter(blog=request.user.blog)
if request.method == 'POST':
title = request.POST.get('title')
content = request.POST.get('content')
category_id = request.POST.get('category')
tag_id = request.POST.getlist('tag')
# 文章简介的获取
desc = content[0:150]
article_obj = models.Article.objects.create(title=title,desc=desc,content=content,category_id=category_id,blog=request.user.blog)
# 下一步添加文章和文章标签表,这个关系表是我们自己创建的无法使用add等方法
# 解决方法自己操作关系表,因为是多对多关系,可能需要创建多条数据 采用了批量插入数据的方法
article_obj_list = []
for i in tag_id:
article_obj_list.append(models.Article2Tag(article=article_obj,tag_id=i))
models.Article2Tag.objects.bulk_create(article_obj_list)
return HttpResponseRedirect('/backend/')
return render(request,'backend/add_article.html',locals())
相关内容
- 我使用pangu模块做了一个文本格式化小工具!,阅读全
- 一篇文章轻松学会python装饰器,通过return关键
- 自动化办公:手机号码提取器,使用正则表达式轻松提
- 用python将网上的文章转存为PDF文档,保存电脑上慢慢看
- Python 读取PDF文件为文本字符并转换为音频,使用pip的方
- Python实现将文本数据批量导入Excel表格,并按格式保存
- Python技能树及CSDN MarkDown编辑器测评,我们在学习的过程
- fastposter v2.8.0 发布 电商海报编辑器,二维码海报,图片
- 用python做一个文本翻译器,自动将中文翻译成英文,超
- Python 自动识别并批量转换文本文件编码,算是个偶尔能
评论关闭