BBS - 后台管理

一、添加文章

注:

后台管理页面,应该有个新得 app

/blog/backend/ # 文章列表页
/blog/add_article/ # 添加文章
# 后台管理
re_path(r'backend/$', views.backend),
re_path(r'add_article/$', views.add_article),

二、文本编辑器

文本编辑器 kindeditor  本质上就是(css+js)
官网:
http://kindeditor.net/demo.php
http://kindeditor.net/doc.php

使用:
<script src="/static/kindeditor/kindeditor-all.js"></script>

<textarea name="article_con" id="article_box" cols="30" rows="10"></textarea>

KindEditor.ready(function (k) {
window.editor = k.create('#article_box')
...
})

KindEditor会覆盖textarea, 注意 id

  初始化 参数

http://kindeditor.net/docs/option.html
  

add_article.html  

注意:kindeditor 参数配置

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>add_article</title>
    <style type="text/css">
        *{padding: 0;margin: 0}
        .header{ width: 100%; height: 60px;background-color: green}
        .content{ padding-top: 30px;}
    </style>
</head>
<body>

<div class="header">

</div>

<div class="content">
    <form action="" method="post">
        {% csrf_token %}
        <div class="title">
            标题: <input type="text" name="title" >
        </div>
        <div>
            内容:<br>
            <textarea name="article_con" id="article_box" cols="30" rows="10"></textarea>
        </div>
        <input type="submit">
    </form>

</div>

{% csrf_token %}
    <script src="/static/js/jquery-3.2.1.min.js"></script>
    <script src="/static/kindeditor/kindeditor-all.js"></script>
    <script charset="utf-8" src="/static/kindeditor/lang/zh-CN.js"></script>

    <script type="text/javascript">
        KindEditor.ready(function (k) {   // 将 自己写得 textarea id=article_box 覆盖
            window.editor = k.create('#article_box',{
                width:800,
                height:400,
                items:[  // 留可选得!!
                    'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
                    'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
                    'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
                    'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
                    'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
                    'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
                    'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
                    'anchor', 'link', 'unlink', '|', 'about'
                ],
                resizeType:0, 
                uploadJson:'upload_img/',
                extraFileUploadParams:{"csrfmiddlewaretoken":$('input[name=csrfmiddlewaretoken]').val()},
                filePostName:'img'
            })
        })

    </script>

</body>
</html>

猜你喜欢

转载自www.cnblogs.com/alice-bj/p/9158412.html
bbs