<!DOCTYPE html>
<html>
<head>
<title>A Simple Page with CKEditor</title>
<!-- 请确保CKEditor文件路径正确 -->
<script src="{{ url_for('static', filename='ckeditor/ckeditor.js') }}"></script>
</head>
<body>
<form>
<textarea name="editor1" id="editor1" rows="10" cols="80">
This is my textarea to be replaced with CKEditor.
</textarea>
<script>
// 用CKEditor替换<textarea id="editor1">
// 使用默认配置
CKEDITOR.replace('editor1');
</script>
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>A Simple Page with CKEditor</title>
<!-- 请确保CKEditor文件路径正确 -->
<script src="{{ url_for('static', filename='ckeditor/ckeditor.js') }}"></script>
</head>
<body>
<form>
<textarea name="editor1" id="editor1" class="ckeditor" rows="10" cols="80">
This is my textarea to be replaced with CKEditor.
</textarea>
</form>
</body>
</html>
<script src="//cdn.ckeditor.com/4.4.6/basic/ckeditor.js"></script>
<script src="//cdn.ckeditor.com/4.4.6/standard/ckeditor.js"></script>
<script src="//cdn.ckeditor.com/4.4.6/full/ckeditor.js"></script>
CKEDITOR.editorConfig = function( config ) {
// ...
// file upload url
config.filebrowserUploadUrl = '/ckupload/';
// ...
};
<script>
CKEDITOR.replace('editor1', {
filebrowserUploadUrl: '/ckupload/',
});
</script>
def gen_rnd_filename():
filename_prefix = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
return '%s%s' % (filename_prefix, str(random.randrange(1000, 10000)))
@app.route('/ckupload/', methods=['POST'])
def ckupload():
"""CKEditor file upload"""
error = ''
url = ''
callback = request.args.get("CKEditorFuncNum")
if request.method == 'POST' and 'upload' in request.files:
fileobj = request.files['upload']
fname, fext = os.path.splitext(fileobj.filename)
rnd_name = '%s%s' % (gen_rnd_filename(), fext)
filepath = os.path.join(app.static_folder, 'upload', rnd_name)
# 检查路径是否存在,不存在则创建
dirname = os.path.dirname(filepath)
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except:
error = 'ERROR_CREATE_DIR'
elif not os.access(dirname, os.W_OK):
error = 'ERROR_DIR_NOT_WRITEABLE'
if not error:
fileobj.save(filepath)
url = url_for('static', filename='%s/%s' % ('upload', rnd_name))
else:
error = 'post error'
res = """
<script type="text/javascript">
window.parent.CKEDITOR.tools.callFunction(%s, '%s', '%s');
</script>
""" % (callback, url, error)
response = make_response(res)
response.headers["Content-Type"] = "text/html"
return response
demo = Blueprint('demo', static_folder="/path/to/static")
<script src="{{url_for('.static', filename='ckeditor/ckeditor.js')}}"></script>
<script type="text/javascript">
CKEDITOR.replace(
"ckeditor_demo", {
filebrowserUploadUrl: './ckupload/'
}
);
</script>
response = form.upload(endpoint=demo)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有