django markdown

2018-06-18 02:14:58来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

1. 编辑器

css

1     <link rel="stylesheet" href="{% static 'plugin/editor.md/css/editormd.css' %}">

 

div

1                 <div id="editormd" class="col-md-10 text-left">
2                     <textarea name="" style="display: none" id="id_body"></textarea>
3 
4                 </div>

提交使用ajax。初次测试使用post内容提交有误

                    <input type="button" class="btn btn-primary btn-lg" value="保存"
                    onclick="publish_article()">

js代码

{% block javasript %}
    <script src="{% static 'plugin/editor.md/editormd.min.js' %}"></script>
    <script>
        $(function () {
            var editor=editormd("editormd",{
                width:"100%",
                height:"640",
                syncScrolling:"single",
                path:"{% static 'plugin/editor.md/lib/' %}"
            });
        })
    </script>



    <script>
    function publish_article() {
        var title=$("#id_title").val();
        var columnid = $("#which_column").val();
        var body = $("#id_body").val();
        $.ajax({
            url:"{% url 'article:article_post' %}",
            type:"POST",
            data:{"title":title,"columnid":columnid,"body":body},
            success:function (args) {
                if(args=="1"){
                    alert("保存完成");
                    location.href="{% url 'article:article_list' %}";
                }else if(args==2){
                    console.log("todo2")
                }else{
                    alert("内容有误,重新填写")
                }
            }
        });
    }
    </script>
{% endblock %}

 

2.查看

{% block head %}
    <link rel="stylesheet" href="{% static 'plugin/editor.md/css/editormd.preview.css' %}">
{% endblock %}


<div id="editormd-view" >
    <textarea name="" id="append-test" style="display: none">
{{ article.body }}
    </textarea>

</div>



{% block javasript %}
    <script src="{% static 'plugin/editor.md/lib/marked.min.js' %}"></script>
    <script src="{% static 'plugin/editor.md/lib/prettify.min.js' %}"></script>
    <script src="{% static 'plugin/editor.md/lib/raphael.min.js' %}"></script>
    <script src="{% static 'plugin/editor.md/lib/underscore.min.js' %}"></script>
    <script src="{% static 'plugin/editor.md/lib/sequence-diagram.min.js' %}"></script>
    <script src="{% static 'plugin/editor.md/lib/flowchart.min.js' %}"></script>
    <script src="{% static 'plugin/editor.md/lib/jquery.flowchart.min.js' %}"></script>
    <script src="{% static 'plugin/editor.md/editormd.min.js' %}"></script>

    <script>
        $(function () {
            editormd.markdownToHTML("editormd-view",{
                htmlDecode:"style,script,iframe",
                emoji:true,
                taskList:true,
                tex:true,
                flowChart:true,
                sequenceDiagram:true,
            });

        });
    </script>
{% endblock %}

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:python+flask 分分钟完美解析阿里云日志

下一篇:Python环境搭建