Skip to content

Commit 80c4475

Browse files
Flask - form , template , api added
1 parent 5b230c7 commit 80c4475

5 files changed

Lines changed: 51 additions & 1 deletion

File tree

Flask/FlaskApi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Hello(Resource):
88
def get(self):
99
return {'about' : 'Hello programmer !'}
1010
def post(self):
11-
postData = request.json()
11+
postData = request.get_json()
1212
return {'You have sent ' : postData}
1313

1414
class Math(Resource):

Flask/Form/Form.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<body>
3+
<form action = "http://localhost:5000/login" method = "post">
4+
<p>Enter Name:</p>
5+
<p><input type = "text" name = "nm" /></p>
6+
<p><input type = "submit" value = "submit" /></p>
7+
</form>
8+
</body>
9+
</html>

Flask/Form/Form.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from flask import Flask, redirect, url_for, request
2+
app = Flask(__name__)
3+
4+
# Redirect Link after getting input from Form
5+
@app.route('/success/<name>')
6+
def success(name):
7+
return 'welcome %s' % name
8+
9+
# To get Data from html form use name parameter in html tag
10+
@app.route('/login',methods = ['POST', 'GET'])
11+
def login():
12+
if request.method == 'POST':
13+
user = request.form['nm']
14+
return redirect(url_for('success',name = user))
15+
else:
16+
user = request.args.get('nm')
17+
return redirect(url_for('success',name = user))
18+
19+
if __name__ == '__main__':
20+
app.run(debug = True)

Flask/Template/Marks.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from flask import Flask, render_template
2+
app = Flask(__name__)
3+
4+
# e.g 127.0.0.1/marks/65
5+
# Default is GET
6+
@app.route('/marks/<int:score>' )
7+
def render_result(score):
8+
return render_template('Marks.html', marks = score)
9+
10+
if __name__ == '__main__':
11+
app.run(debug = True)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<html>
3+
<body>
4+
{% if marks>50 %}
5+
<h1> Your result is pass!</h1>
6+
{% else %}
7+
<h1>Your result is fail</h1>
8+
{% endif %}
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)