django 使用markdown编辑器

郁隐水
2023-12-01

1.编辑

下载地址https://github.com/pandao/editor.md

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

......

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

{% 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. 显示

转载于:https://blog.51cto.com/13606158/2095234

 类似资料: