Skip to content
Snippets Groups Projects
Commit 8f780e5b authored by aslesha's avatar aslesha
Browse files

Update flask.py

parent cc57e8f0
No related branches found
No related tags found
No related merge requests found
from flask import Flask, redirect, url_for, render_template
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
@app.route('/about')
def about():
return 'About Page'
@app.route('/Name/')
@app.route('/Name/<name>')
def displayName(name):
if name is None:
return 'No Name '
else:
return 'My Name is %s' %name
@app.route('/Number/<int:reg_no>') # float can also be used
def displayNo(reg_no):
return "Your Regnumber is %d" %reg_no
@app.route('/admin')
def hello_admin():
return 'Hello Admin'
@app.route('/guest/<guest>')
def hello_guest(guest):return 'Hello %s as Guest' % guest
@app.route('/user/<name>')
def hello_user(name):
if name == 'admin':
return redirect(url_for('hello_admin'))
else:
return redirect(url_for('hello_guest', guest=name))
@app.errorhandler(404)
def notfound():
print("Not found Error")
return "not found"
@app.route('/hello/<user>')
def hello_name(user):
return render_template('hello.html', name = user)
@app.route('/result')
def result():
dict = {'phy':50,'che':60,'maths':70}
return render_template('hello.html', result = dict)
@app.route('/blog')
def prac():
user = {'username': 'AmritaCSE'}
posts=[
{'author': {'username': 'DK'}, 'msg': 'MS Dhoni Is A Topper In University Where I Am Still Studying'},
{'author': {'username': 'Rajinikanth'},
'msg': 'Tamil Nadu is a secular place and we must spare no effort toensure communal harmony'}
]
return render_template('blog.html',result=posts,name=user)
if __name__ == '__main__':
app.run(debug=True)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment