TypeError:视图函数未返回有效响应。该函数返回None或不返回return语句而结束

时间:2018-07-08 23:00:29

标签: python flask plotly-dash

我正在尝试在Flask应用程序内部构建Dash应用程序,并且获得了以下完整的Traceback:

Traceback (most recent call last):
File "/Users//ds/lib/python3.6/site-packages/flask/app.py", line 2292, 
in wsgi_app
response = self.full_dispatch_request()
File "/Users/ds/lib/python3.6/site-packages/flask/app.py", line 1816, in 
full_dispatch_request
return self.finalize_request(rv)
File "/Users/ds/lib/python3.6/site-packages/flask/app.py", line 1831, in 
finalize_request
response = self.make_response(rv)
File "/Users/ds/lib/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.

这是我的app.py:

from flask import Flask
import os
import dash
import flask

server = flask.Flask(__name__)
app = dash.Dash(__name__) 

basedir = os.path.abspath(os.path.dirname(__file__))

这是我的观点。py

from flask import Flask, request, render_template, flash, redirect, 
session, url_for, g, jsonify, make_response
from werkzeug.datastructures import CombinedMultiDict
from werkzeug.utils import secure_filename
from app import server, app 
from app import db
from models import User, Post
import os 
from dash import Dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, State, Output
import pandas as pd
import plotly.graph_objs as go
from analysis import * 

@server.route('/index', methods=['GET','POST']) 

def index():

    app.layout = html.Div([
       dcc.Graph( ... [[ My Dash App Code ]]  )

这是我的奔跑。py

from app import server, app
server.run(debug=True)

我很确定我不需要在视图中返回render_template即可使其正常工作,但也许不是吗?任何帮助将不胜感激!

0 个答案:

没有答案