1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

HTMLテーブルからFLASKへのPOST送信

1
Last updated at Posted at 2019-11-05

HTMLテーブルをJSON変換して、バックエンドでポスト受信して、CSV保存をする処理を書いています。

いまCSVファイルのファイル名を、JSONのポストデータに、プラスワンして渡そうとしていますが、
ここではフォームを使わず、JS側のFUNCTIONでPOST送信しています。

ファイル名を渡す方法はないものでしょうか?

@app.route('/csvout', methods=['POST'])
def csvout():

    if request.method == 'POST':
        pdb.set_trace()
        df_s = pd.read_json(request.data)

        filename = request.form["upload_file"]  ← これが使えない
        df.to_csv("data.csv")
        return render_template('edit1.html', fname=filename, csvname=csvn)
    else:
        return redirect('/')
<script type="text/javascript">

		function loading() {

			var data = $('#target').tableToJSON();

			$.ajax({
				type: "POST",
				url: "/csvout",
				contentType: 'application/json; charset=UTF-8',
				data: JSON.stringify(data),
				dataType: 'json',
				success: function (data) {
					console.log(data);
				},
				error: function (error) {
					console.log(error);
				},
			});
		}


	</script>
1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?