Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python uwsgi错误日志显示flask TypeError:view函数未返回有效响应_Python_Flask_Uwsgi - Fatal编程技术网

Python uwsgi错误日志显示flask TypeError:view函数未返回有效响应

Python uwsgi错误日志显示flask TypeError:view函数未返回有效响应,python,flask,uwsgi,Python,Flask,Uwsgi,我正在学习编写python代码。 我的flask应用程序使用owm web服务器是可以的。但是,使用nginx+uwsgi+flask部署时,uwsgi错误: [2018-09-05 18:28:59,295] ERROR in app: Exception on /editor [GET] Traceback (most recent call last): File "/usr/lib64/python3.6/site-packages/flask/app.py", line 2

我正在学习编写python代码。 我的flask应用程序使用owm web服务器是可以的。但是,使用nginx+uwsgi+flask部署时,uwsgi错误:

    [2018-09-05 18:28:59,295] ERROR in app: Exception on /editor [GET]
Traceback (most recent call last):
  File "/usr/lib64/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib64/python3.6/site-packages/flask/app.py", line 1816, in full_dispatch_request
    return self.finalize_request(rv)
  File "/usr/lib64/python3.6/site-packages/flask/app.py", line 1831, in finalize_request
    response = self.make_response(rv)
  File "/usr/lib64/python3.6/site-packages/flask/app.py", line 1957, in make_response
    'The view function did not return a valid response. The'
TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.
我的flask代码是flaskr示例。代码如下:

# coding=utf-8
"""
    ~~~~~~
    A microblog example application written as Flask tutorial with
    Flask and sqlite3.
    :copyright: (c) 2010 by Armin Ronacher.
    :license: BSD, see LICENSE for more details.
"""

from sqlite3 import dbapi2 as sqlite3
from flask import Flask, request, session, g, redirect, url_for, abort, \
     render_template, flash


# create our little application :)
app = Flask(__name__)

# Load default config and override config from an environment variable
app.config.update(dict(
    DATABASE='/tmp/flaskr.db',
    DEBUG=False,
    SECRET_KEY='development key',
    USERNAME='admin',
    PASSWORD='default'
))
app.config.from_envvar('FLASKR_SETTINGS', silent=True)


def connect_db():
    print ("connect db")
    """Connects to the specific database."""
    rv = sqlite3.connect(app.config['DATABASE'])
    rv.row_factory = sqlite3.Row
    return rv


def init_db():
    """Creates the database tables."""
    with app.app_context():
        db = get_db()
        with app.open_resource('schema.sql', mode='r') as f:
            db.cursor().executescript(f.read())
            print("excute sql")
        db.commit()


def get_db():
    """Opens a new database connection if there is none yet for the
    current application context.
    """
    if not hasattr(g, 'sqlite_db'):
        g.sqlite_db = connect_db()
    return g.sqlite_db


@app.teardown_appcontext
def close_db(error):
    """Closes the database again at the end of the request."""
    if hasattr(g, 'sqlite_db'):
        g.sqlite_db.close()


@app.route('/')
def show_entries():
    db = get_db()
    cur = db.execute('select title, text from entries order by id desc')
    entries = cur.fetchall()
    return render_template('show_entries.html', entries=entries)

@app.route('/logout')
def logout():
    session.pop('logged_in', None)
    flash('You were logged out')
    return redirect(url_for('show_entries'))

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

if __name__ == '__main__':
    init_db()
    app.run(host='0.0.0.0')

其他视图功能正常。只有edtior视图功能错误。但只运行烧瓶是可以的。添加nginx和uwsgi是错误的。

我重新启动uswgi,编辑器视图功能工作。可能是因为uwsgi无法检测python代码的变化