再国内,做什么都这么吃力。连aliyun 的ssh 都被封这是什么世道,所以做一个在线编辑代码的
忙忙碌碌有点粗糙。大家见谅
​1. [代码]views.py

#-*- coding:utf-8 -*- 
# jQuery File Tree
# Python/Django connector script
# By Martin Skou
#
import os
import urllib
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
 
def index(request):
    if not request.user.is_superuser:
       return HttpResponse(u"不要乱来")
    return render(request, 'codemirror/index.html', {"foo": "bar"},
        content_type="text/html")
          
 
def openfile(request):
    if not request.user.is_superuser:
       return HttpResponse(u"不要乱来")
    path = request.GET['path']
     
    f = open(path)
    con = f.read()
    f.close()
     
    return render(request, 'codemirror/openfile.html', {"con": con, "path":path},
        content_type="text/html")
 
@csrf_exempt
def savefile(request):
    if not request.user.is_superuser:
       return HttpResponse(u"不要乱来")
    path = request.POST['path']
    con = request.POST['con']
     
    f = open(path, 'wr')
    f.write(con.encode('utf-8'))
    f.close()
     
    return HttpResponse('成功')
     
@csrf_exempt
def createfile(request):
    if not request.user.is_superuser:
       return HttpResponse(u"不要乱来")
    path = request.GET['path']
 
    f = open(path, 'wr')
    f.write('')
    f.close()
 
    return HttpResponse('成功')
         
@csrf_exempt
def dirlist(request):
   if not request.user.is_superuser:
       return HttpResponse(u"不要乱来")
   r=['<ul class="jqueryFileTree" >']
   try:
       r=['<ul class="jqueryFileTree" >']
       d=urllib.unquote(request.POST.get('dir','c:\\temp'))
       for f in os.listdir(d):
           ff=os.path.join(d,f)
           if os.path.isdir(ff):
               r.append('<li class="directory collapsed"><a href="#" rel="%s/">%s</a></li>' % (ff,f))
           else:
               e=os.path.splitext(f)[1][1:] # get .ext and remove dot
               r.append('<li class="file ext_%s"><a href="#" rel="%s">%s</a></li>' % (e,ff,f))
       r.append('</ul>')
   except Exception,e:
       r.append('Could not load directory: %s' % str(e))
   r.append('</ul>')
   return HttpResponse(''.join(r))
2. [代码]urls.py

#-*- coding:utf-8 -*-
from django.conf.urls.defaults import patterns, url
 
urlpatterns = patterns('codemirror.views',
    url(r'^dirlist.html$', 'dirlist'),
    url(r'^index.html$', 'index'),
    url(r'^openfile.html$', 'openfile'),
    url(r'^savefile.html$', 'savefile'),
    url(r'^createfile.html$', 'createfile'),
     

3. [代码]index.html

<html>
<head>
    <script type="text/javascript" src="/static/js/jquery-1.9.0.min.js"></script>
    <link href="/static/codemirror-3.16/lib/codemirror.css" rel="stylesheet">
    <script type="text/javascript" src="/static/codemirror-3.16/lib/codemirror.js"></script> 
     
    <script type="text/javascript" src="/static/jqueryFileTree/jqueryFileTree.js"></script>
    <link href="/static/jqueryFileTree/jqueryFileTree.css" rel="stylesheet">
     
    </head>
<body>
 
<h1>
 
 
<p>My first paragraph.</p>
 
<div id="file_tree_div_id" >
</div>
<iframe id="editor_iframe_id" src="" ></iframe>
<script type="text/javascript">
  
$(document).ready( function() {漫画图片
    /* $.get('/codemirror/dirlist.html?dir=/home/boneyao/', function(html){
        $('#file_tree_div_id').html(html);
    });*/http://www.bizhizu.cn/manhua/​
     
    $(document).ready( function() {
        $('#file_tree_div_id').fileTree({
            root: '/home/boneyao/',
            script: '/codemirror/dirlist.html?dir=/home/boneyao/',
            expandSpeed: 1000,
            collapseSpeed: 1000,
            multiFolder: false
        }, function(file) {
           $('#editor_iframe_id').attr('src', "http://www.boneyao.com/codemirror/openfile.html?path="+file);
    });
});
});
 
   /*
  var editor = CodeMirror.fromTextArea(myTextarea, {
    mode: "text/html"
  });*/
 
 
</script>
 
</body>
</html>
4. [代码]openfile.html     
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="/static/js/jquery-1.9.0.min.js"></script>
    <link href="/static/codemirror-3.16/lib/codemirror.css" rel="stylesheet">
    <script type="text/javascript" src="/static/codemirror-3.16/lib/codemirror.js"></script> 
    <script type="text/javascript" src="/static/codemirror-3.16/mode/python/python.js"></script> 
    <script type="text/javascript" src="/static/codemirror-3.16/mode/javascript/javascript.js"></script>
     
    <script type="text/javascript" src="/static/jqueryFileTree/jqueryFileTree.js"></script>
    <link href="/static/jqueryFileTree/jqueryFileTree.css" rel="stylesheet">
     
    </head>
<body>
<input type="button" value="保存" onclick="save()"/></h1>
<TextArea id="myTextarea" >
{{con}}
</TextArea>
<script type="text/javascript">
var mode = "";
 
switch(window.location.href.split('.').slice(-1)[0]){
    case 'py': mode='python';break;
    case 'js': mode='javascript';break;
}
var editor = CodeMirror.fromTextArea($('#myTextarea')[0], {
    mode: mode
});
editor.setSize('100%','100%');
 
 
function save(){
    var value = editor.getValue();
     
    $.post('http://www.boneyao.com/codemirror/savefile.html', {
        'path':"{{path}}",'con':value
    }, function(text){
        alert(text);
    });
};
</script>
 
</body>
</html>

5. [图片] 2.bmp

在线编辑代码[django]版本的更多相关文章

  1. [个人开源]vue-code-view:一个在线编辑、实时预览的代码交互组件

    组件简介 vue-code-view是一个基于 vue 2.x.轻量级的代码交互组件,在网页中实时编辑运行代码.预览效果的代码交互组件. 使用此组件, 不论 vue 页面还是 Markdown 文档中 ...

  2. RunJS - 在线编辑、展示、分享、交流你的 JavaScript 代码

    发现一个很好玩,很强大的网站 RunJS - 在线编辑.展示.分享.交流你的 JavaScript 代码   http://runjs.cn/ 比如: http://runjs.cn/detail/l ...

  3. 花了一年时间完成的 在线G代码编辑,加工系统 G-Code Editor V1.0

    G代码是数控程序中的加工指令.一般都称为G指令.可以直接用来驱动机床,各种控制系统.是一种数控行业标准.传统的G代码编写以及编辑无法在线编辑,也不能实时看到g代码编辑的最后加工路径已经不能直接对编辑的 ...

  4. 一个很好用的在线编辑、展示、分享、交流JavaScript 代码的平台

    在发表博客时,有一些代码只能粘贴进去,而不能看到代码运行的效果,需要读者把代码粘贴进自己的编辑器,然后再运行看效果,这是一件很耗时的事情 在平时百度的时候,我发现一些网站可以在线预览功能,而且可以在线 ...

  5. 在线编辑word文档代码

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  6. java 网站源码 在线编辑模版 代码编辑器 兼容手机平板PC freemaker 静态引擎

    前台: 支持四套模版, 可以在后台切换   系统介绍: 1.网站后台采用主流的 SSM 框架 jsp JSTL,网站后台采用freemaker静态化模版引擎生成html 2.因为是生成的html,所以 ...

  7. Office文档在线编辑的实现之二

    讲述了如何通过iis的webdav支持实现客户端的office直接编辑服务器上的文件,本篇将讲解如何实现客户端的office直接编辑数据库中的二进制形式保存的office文件. 实现的关键:模拟IIS ...

  8. 使用WebDAV实现Office文档在线编辑

    Office的文档处理能力是非常强大的,但是它是本地资源,在Office Web App尚未成熟前,仍需要使用本地能力来进行文档编辑,可是现代的系统的主流却是B/S,所以在B/S中调用本地的Offic ...

  9. C# 10分钟入门基于WebOffice实现在线编辑文档,实时保存到服务器(所有office,兼容WPS)

    今天,他来了(weboffice在线编辑文档). 上次写了一个在线预览的博,当然,效果并不是太理想,但是紧急解决了当时的问题. 后来,小编重新查找资料,求助大牛,终于使用新的方式替换了之前的low方法 ...

随机推荐

  1. GNU LD 脚本学习笔记

    LD脚本(linker script)是什么 GNU ld是链接器,ld实际并不是GCC的一部分,ld属于binutils软件包.但是嵌入式开发时,下载的linaro GCC工具集中是包含 arm-l ...

  2. leetCode 50.Pow(x, n) (x的n次方) 解题思路和方法

    Pow(x, n) Implement pow(x, n). 思路:题目不算难.可是须要考虑的情况比較多. 详细代码例如以下: public class Solution { public doubl ...

  3. Weka学习之认识weka(一)

     Weka 简介   WEKA作为一个公开的数据挖掘工作平台,集合了大量能承担数据挖掘任务的机器学习算法,包括对数据进行预处理,分类,回归.聚类.关联规则以及在新的交互式界面上的可视化. Weka是基 ...

  4. eclipse JVM Tomcat 内存堆栈大小设置

    1,  设置Eclipse内存使用情况 修改eclipse根目录下的eclipse.ini文件 -vmargs  //虚拟机设置 -Xms40m //初始内存 -Xmx256m //最大内存 -Xmn ...

  5. linux heads分析(转)

    内核默认的运行地址为PHY_OFFSET+0x8000,即物理地址开始后的0x8000字节处,前面是留给参数用的.参数以atag方式存储,默认放在0x100偏移位置. http://blog.chin ...

  6. erlang 最大公约数

    一般面试会遇到问一些算法,什么排序,树,图等等,冷不丁还会问几个蛋疼的问题,我估计生产情况十有八九都用不上,只是题目罢了. 题目:求两个大数的最大公约数. 什么是最大公约数呢? 百度百科的答案这样的: ...

  7. PHP SOCKET编程 .

    1. 预备知识 一直以来很少看到有多少人使用php的socket模块来做一些事情,大概大家都把它定位在脚本语言的范畴内吧,但是其实php的socket模块可以做很多事情,包括做ftplist,http ...

  8. 06 nginx Location详解之精准匹配

    一:Location详解之精准匹配 location 语法 location 有”定位”的意思, 根据Uri来进行不同的定位. 在虚拟主机的配置中,是必不可少的,location可以把网站的不同部分, ...

  9. 通俗的解释下音视频同步里pcr作用

    PCR同步在非硬件精确时钟源的情况还是谨慎使用,gstreamer里面采用PCR同步,但是发现好多ffmpeg转的片儿,或者是CP方的片源,pcr打得很粗糙的,老是有跳帧等现象.音视频同步,有三种方法 ...

  10. mysql 考勤表异常 【待修改】

    有考勤刷卡记录表,表名为attendance ,有如下字段: 姓名 卡号 刷卡时间 刷卡类型 name id time type    张三 59775623 2010-04-01 07:23:37  ...