0) Do not use uppercase for vars. Uppercase is always for constants.
1) Use routes with "/" at the end to avoid additional redirects which flask does:
@app.route('/user_input/', methods = ['POST'])
2) Use the same route and the same function to get what you need:
from flask import Flask, request, render_template, jsonify
def json_response(status_code, data):
res = jsonify(data)
res.status_code = status_code
return res
app = Flask(__name__)
@app.route('/user_input/', methods=["GET", "POST"])
def user_input():
if request.method == "GET":
return render_template('user-input.html')
else:
python_dictionary = {'bookName': request.form.get('Book_Name'),
'page': request.form.get('Page'),
'text': request.form.get('Text'),
'topic': request.form.get('Topic')}
return json_response(200, python_dictionary)
app.run()
3) And yes, you don't need to use json.dumps(pythonDictionary) before passing dictionary to jsonify
4) Consider to use request.form.get('key') rather than request.form['key'] because get() function returns None if there is no such key:value instead of raising key error exception.