Question 30
A Python file and two HTML files are given below.
File 1: main.py
from flask import Flask, render_template, make_response, request
app=Flask(__name__)
@app.route('/home')def myHome(): return render_template('form.html')
@app.route('/setmycookie', methods = ['GET', 'POST'])def setMyCookie(): if request.method == 'POST': input = request.form['name1']
res = make_response(render_template('index.html')) res.set_cookie('Fruit', input) return res
@app.route('/getmycookie')def getMyCookies(): val= request.cookies.get('Fruit') return 'My favorite fruit is '+ valif __name__ == '__main__': app.run(debug=True)File 2: form.html
<!DOCTYPE html><head></head><html> <body> <form action = '/setmycookie' method = 'POST'> <h3>Your Input: <input type = 'text' name = 'name1'/></h3> <h3><input type = 'submit'</h3> </form>
</body></htmlFile 3: index.html
<!DOCTYPE html><head></head><html> <body> <h1> Cookies are now being set.</h1> </body></html>Which of the following statements is/are true, if the above application is running on URL the “http://127.0.0.1:5000”?
Whenever we hit the URL ‘http://127.0.0.1:5000/’, a form with one input field will get open.
On the URL ‘http://127.0.0.1:5000/home’, when we click on submit button after filling the form, it will display “Cookies are now being set.” on the webpage.
Whenever we submit the form, it will remain on the URL ‘/home’ itself.
Whenever we give ‘Apple’ as input to the form, thus on hitting the URL
‘http://127.0.0.1:5000/getmycookie’, it will show ‘My favorite fruit is Apple’ on the screen.