Python 如何从TinyMCE到flask视图获取数据

Python 如何从TinyMCE到flask视图获取数据,python,twitter-bootstrap,flask,tinymce,Python,Twitter Bootstrap,Flask,Tinymce,我有一个文本编辑器表单-TinyMCE,但不能让它将文本传递给flask view函数。我使用本教程添加了文本编辑器。TinyMCE使用引导。My app.py文件: from flask import Flask, render_template, request app = Flask(__name__) @app.route('/') def index(): editor = request.args.get("editor") print(editor)

我有一个文本编辑器表单-TinyMCE,但不能让它将文本传递给flask view函数。我使用本教程添加了文本编辑器。TinyMCE使用引导。My app.py文件:

from flask import Flask, render_template, request

app = Flask(__name__)


@app.route('/')
def index():
    editor = request.args.get("editor")
    print(editor)
    return render_template('index.html')

@app.route('/see_posts', methods=['POST'])
def see_posts():
    editor = request.args.get('editor')
    return "<p>"+editor+'</p>'


if __name__ == '__main__':
    app.run()
从烧瓶导入烧瓶,呈现模板,请求
app=烧瓶(名称)
@应用程序路径(“/”)
def index():
editor=request.args.get(“编辑器”)
印刷(编辑)
返回渲染模板('index.html')
@app.route('/see_posts',methods=['POST'])
def请参阅_posts():
editor=request.args.get('editor')
返回“”+编辑器+”

' 如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu': app.run()
My index.html文件:

{% extends "base.html" %}

{% block content %}
    <script src="https://cdn.tiny.cloud/1/r55dmb7tylbap7uwxto0jlsvcn6z3uy29kieq6ujtxejkzyi/tinymce/5/tinymce.min.js" referrerpolicy="origin"></script>

<script>
  tinymce.init({
    selector: 'textarea#editor',
    menubar: false
  });
</script>
<div class="container mt-4 mb-4">
  <div class="row justify-content-md-center">
    <div class="col-md-12 col-lg-8">
     <form action = {{ url_for('see_posts') }} method='POST'}}>
      <h1 class="h2 mb-4">Submit issue</h1>
      <label>Describe the issue in detail</label>
      <div class="form-group">

         <textarea id="editor" name = editor></textarea>
      </div>
      <button type="submit" class="btn btn-primary">Submit</button>
     </form>
    </div>
  </div>
</div>
{% endblock %}
{%extends“base.html”%}
{%block content%}
tinymce.init({
选择器:“文本区域#编辑器”,
菜单栏:错误
});
提交问题
详细描述这个问题
提交
{%endblock%}

我添加了表单操作,但它没有帮助。我得到的错误是
TypeError:无法将'NoneType'对象隐式转换为str
,因此表单不被view函数解析。

您将数据发布在表单中,而不是请求参数。您需要查看flask.request.form中的

HTML


提交
烧瓶

从flask导入请求,呈现\u模板
@应用程序路径(“/”)
def index():
返回渲染模板('index.html')
@app.route('/see_posts',methods=['POST'])
def请参阅_posts():
editor=request.form['editor']
返回“”+编辑器+”

'
您发布的是表单中的数据,而不是请求参数。您需要查看flask.request.form中的

HTML


提交
烧瓶

从flask导入请求,呈现\u模板
@应用程序路径(“/”)
def index():
返回渲染模板('index.html')
@app.route('/see_posts',methods=['POST'])
def请参阅_posts():
editor=request.form['editor']
返回“”+编辑器+”

'
您也不需要用
元素包装编辑器,
编辑器
输出很可能已经包含
元素。您也不需要用
元素包装编辑器,
编辑器
输出很可能已经包含
元素
<form action="{{ url_for('see_posts') }}" method='POST'}}>
    <textarea id="editor" name="editor"></textarea>
    <button type="submit">Submit</button>
</form>
from flask import request, render_template
@app.route('/')
def index():
    return render_template('index.html')

@app.route('/see_posts', methods=['POST'])
def see_posts():
    editor = request.form['editor']
    return  "<p>"+editor+'</p>'