发表文章

这节主讲的是如何利用在线编辑器发表文章

主要动作有  在页面网页中配置出编辑文章视图->将文章上传到后台数据库

一:在网页上配置出编辑文章视图

1.这里我用的是ueditor,主要配置参考相关文章

2.在网页上添加自己的提交按钮,如图

<!DOCTYPE html>
<html>
<head>
	<title>Live for interesting</title>
	<meta charset="utf-8">
<script type="text/javascript" charset="utf-8" src="static/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="static/ueditor/ueditor.all.js"></script>
</head>
<body>

<form action="../editor" method="POST">
<div>
	<span class="cTit">标题:</span>
	<input name="title" type="text" size="96" value=""><br>
	<span class="cTit">主题:</span>
	<input name="summary" type="text" size="96" value="">
	
	<textarea id="editor" name="container" style="width: 800px; height: 400px; margin: 0 auto;"></textarea>
	<input type="submit" value="提交">
</div>	
</form>

</body>
<script type="text/javascript">
		var ue=UE.getEditor('editor');
</script>	

</html>

二:将上传的数据写往数据库

def editor(req):
	models.LFI.objects.create(
		title=req.POST.get("title"),
		category=models.Category.objects.get(id=1),
		summary=req.POST.get("summary"),
		content=req.POST.get("container"),
		author=models.LFI_user.objects.get(user=req.user),
		view_count=0,
		ranking=0
	)
	return render_to_response("editor.html")

你可能感兴趣的:(Web,django,python)