富文本在django中的使用

1、配置

在django中使用富文本编辑器需安装django-tinymce模块

安装指令:pip install django-tinymce

在setting中进行配置,在setting的最后加上:

TINYMCE_DEFAULT_CONFIG = {
			'theme':'advanced',
			'width':800,
			'height':600,
		}

最后,在setting的INSTALLED_APPS中加上 'tinymce',

2、在视图函数中使用富文本

def testRTF(request):
    return render(request, 'testRTF.html')
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src='/static/tiny_mce/tiny_mce.js'></script>
	<script>
		tinyMCE.init({
			'mode':'textareas', 'theme':'advanced',
			'width':800,'height':600,
		})
	</script>
</head>
<body>
<form method='post' action='url'>
		<textarea></textarea>
	</form>
</body>
</html>

在模板中添加script,其中width与height可随要求修改

    <script src='/static/tiny_mce/tiny_mce.js'></script>
	<script>
		tinyMCE.init({
			'mode':'textareas', 'theme':'advanced',
			'width':800,'height':600,
		})
	</script>

在表单中添加文本域

<form method='post' action='url'>
		<textarea></textarea>
</form>

最后附上效果图:

猜你喜欢

转载自blog.csdn.net/pyrans/article/details/82776888