簡體   English   中英

錯誤在哪里?“視圖函數未返回有效響應。 ”在我的燒瓶應用程序中?

[英]Where is the error “The view function did not return a valid response. ” in my flask app?

錯誤

(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>

首先,我在app.py上添加了函數dataset並運行它。 這個應用程式還可以,它對我來說適用於有效載荷csv,但是當我單擊另一個chart.html (例如chart.html並返回頁面dataset.html ,就會發生錯誤。 請幫我解決這個問題

正如我在評論部分中提到的:

當您的所有if語句都不滿足時,數據集函數將返回None,這不是有效的響應。 只需在數據集函數的末尾添加默認行為即可。 如果將其視為錯誤/有害行為,則可能應該return render_template('dataset.html')return render_template('error_page.html')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM