错误
(app) E:\skripsi_app>python app.py
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [03/Mar/2019 22:17:11] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [03/Mar/2019 22:17:16] "POST / HTTP/1.1" 200 -
[2019-03-03 22:17:17,884] ERROR in app: Exception on /dataset [GET]
Traceback (most recent call last):
File "E:\skripsi_app\app\lib\site-packages\flask\app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "E:\skripsi_app\app\lib\site-packages\flask\app.py", line 1816, in full_dispatch_request
return self.finalize_request(rv)
File "E:\skripsi_app\app\lib\site-packages\flask\app.py", line 1831, in finalize_request
response = self.make_response(rv)
File "E:\skripsi_app\app\lib\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.
127.0.0.1 - - [03/Mar/2019 22:17:17] "GET /dataset HTTP/1.1" 500 -
app.py中的数据集功能
@app.route('/dataset',methods=['GET','POST'])
def dataset():
if request.method == 'POST':
file = request.files['file']
if 'file' not in request.files:
return redirect(request.url)
if file.filename == '':
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return render_template('dataset.html')
以html
<strong>Upload Data</strong>
<br>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="file">
<button type="submit" value="Upload File" class="btn btn-primary">Upload</button>
</form>
首先,我在dataset
上添加了函数app.py
并运行了它。这个应用程式还可以,对我来说适用于有效载荷csv,但是当我单击另一个链接,例如chart.html
并返回页面dataset.html
时,就会发生错误。
请帮我解决这个问题
答案 0 :(得分:1)
正如我在评论部分中提到的:
当您的所有if语句都不满足时,数据集函数将返回None,这不是有效的响应。只需在数据集函数的末尾添加默认行为即可。如果您将其视为错误/不良行为,则可能应该为return render_template('dataset.html')
或return render_template('error_page.html')
。