uwsgi错误日志显示烧瓶类型错误:视图函数未返回有效响应[重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我正在学习编写python烧瓶代码。我的烧瓶应用程序使用owm web服务器是可以的。 Howerver,使用nginx + uwsgi + flask deploy,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.

我的烧瓶代码是烧瓶的例子。代码如下:

# 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是错误的。

python flask uwsgi
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.