Django 使用UEditor

Django package 的一些包不支持upload file, 而且 有几个支持的不是收费的就是要开csrf ,这对于苦逼程序猿来说始终是件恼火的事。所以经过查阅各种资料。看了各种各样的配置doc, 最终搞定了django + Ueditor (开源,含upload file 功能的组件)以下粗略写了些步骤:

1. your html page

<head>
<!--FOR UEDITOR -->
<script type="text/javascript" charset="utf-8">
 window.UEDITOR_HOME_URL = window.UEDITOR_HOME_URL||"/Ueditor/ueditor/";
</script>


<script type="text/javascript" charset="utf-8" src="/static/Ueditor/ueditor/editor_config.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/Ueditor/ueditor/editor_all_min.js"></script>
<link rel="stylesheet" type="text/css" href="/static/Ueditor/ueditor/themes/default/ueditor.css"/>
<!--FOR UEDITOR -->

</head>​

<form>

          <p>
              <label>提案内容</label>
              <textarea class="text-input textarea" id="proposal_content" name="proposal_content" cols="79" rows="15"></textarea>
            </p>
            <p>
​
</form>

after form 


    
   <!-- for ueditor-->
    <script type="text/javascript">
        var ue=new UE.ui.Editor();
        ue.render('proposal_content');
    </script>
    <!--for ueditor-->
​2.in uedior.views:

#coding:utf-8

from proposal_platform import settings         #using your project root settings 
from django.core.context_processors import csrf
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template.context import RequestContext
from django.views.decorators.csrf import csrf_exempt
from PIL import Image  # help to create  uplaoded bitmap 
import base64
import os
import time
import urllib2
import uuid
from django.utils.encoding import smart_unicode
​

3.urlconfig:
(
    # for UEditor {{
    url(r'^ueditor_imgup$', 'proposal_platform.UeditorApp.Ueditor.views.ueditor_ImgUp'),
    url(r'^ueditor_fileup$', 'proposal_platform.UeditorApp.Ueditor.views.ueditor_FileUp'),
    url(r'^ueditor_getRemoteImage$', 'proposal_platform.UeditorApp.Ueditor.views.ueditor_getRemoteImage'),
    url(r'^ueditor_scrawlUp$', 'proposal_platform.UeditorApp.Ueditor.views.ueditor_ScrawUp'),
    url(r'^ueditor_getMovie$', 'proposal_platform.UeditorApp.Ueditor.views.ueditor_getMovie'),
    url(r'^ueditor_imageManager$', 'proposal_platform.UeditorApp.Ueditor.views.ueditor_imageManager'),
    # }}
​
    # 这里是否使用/admin/aaa.html的请求 ,假设有静态网页的请求要在里面单独设计 {{
    url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
    url(r'^(?!admin)(?

P<path>.*)$','django.views.static.serve', {'document_root': settings.STATIC_ROOT}), url(r'^(?

P<path>.*)$', 'django.views.static.serve', {'document_root': settings.ADMIN_HTML_ROOT}), # }} ​) if settings.DEBUG is False: urlpatterns += patterns('', url(r'^static/(?P<path>.*)$', 'django.views.static.serve', { 'document_root': settings.STATIC_ROOT }), ) ​


4.the full dir of the project:




【推广】 免费学中医,健康全家人
原文地址:https://www.cnblogs.com/ldxsuanfa/p/10655418.html