2017-02-26 6 views
0

下の人は私のフラスコアプリケーションからの私の見解です。私は自分のアプリケーションにファイルをアップロードしていた場合、それは示されたが、応答して、それは""ValueError: View function did not return a response""フラスコ "ValueError:jsonファイルへの書き込み時にView関数が応答を返しませんでした"

@app.route('/') 
def upload_file_mainpage(): 
    return render_template('index.html') 


@app.route('/uploader', methods=['GET', 'POST']) 
def upload_file(): 
    if request.method == 'POST': 
     new_file = request.files['file'] 
     outfile = open('out.json', 'w') 
     with outfile as outfile: 
      return json.dump(soupla(new_file), outfile), 200 

souplaは、私はそれで問題はないと私はjson.dumps(soupla(new_file))を使用する場合でも、それは正確に返す辞書を返すというエラーが返されたJSONファイルに辞書を書き込み私が望むものしかし、ファイルに書き込むことはできません。linkを使って辞書をjsonファイルに書き出しました。

答えて

1

あなたは2つのことをしたいようです。データをファイルに書き出し、そのデータを応答に戻したいとします。両方を行うには、2つのステップを実行する必要があります。例えば

@app.route('/') 
def upload_file_mainpage(): 
    return render_template('index.html') 


@app.route('/uploader', methods=['GET', 'POST']) 
def upload_file(): 
    if request.method == 'POST': 
     new_file = request.files['file'] 
     rv = json.dumps(soupla(new_file)) 
     outfile = open('out.json', 'w') 
     with outfile as outfile: 
      outfile.write(rv) 
     return rv, 200 
関連する問題