Advertisement
LeonardCHoo

webapp_template.py

Jul 17th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.44 KB | None | 0 0
  1. """
  2.  
  3. CHOO SANGBUEM
  4. 71675619
  5.  
  6. Added  @app.route('/derek')
  7. which loads templates/sample.html
  8.  
  9.  
  10.  
  11. """
  12.  
  13.  
  14. from flask import Flask, request, render_template
  15.  
  16. def do_the_login(username, password):
  17.     return "logging in user: %s, pass: %s" % (username, password)
  18.  
  19. def show_the_login_form():
  20.     return "show the login form"
  21.  
  22. app = Flask(__name__)
  23.  
  24. @app.route('/')
  25. def index():
  26.     return 'Index Page'
  27.  
  28. @app.route('/hello')
  29. def hello():
  30.     return 'Hello, World'
  31.  
  32. @app.route('/user/<username>')
  33. def show_user_profile(username):
  34.     # show the user profile for that user
  35.     return 'User %s' % username
  36.  
  37. #int is the type and
  38. @app.route('/post/<int:post_id>')
  39. def show_post(post_id):
  40.     # show the post with the given id, the id is an integer
  41.     return 'Post %d' % post_id
  42.  
  43. @app.route('/path/<path:subpath>')
  44. def show_subpath(subpath):
  45.     # show the subpath after /path/
  46.     return 'Subpath %s' % subpath
  47.  
  48. @app.route('/projects/')
  49. def projects():
  50.     return 'The project page'
  51.  
  52. @app.route('/login', methods=['GET','POST'])
  53. def login():
  54.     if request.method == 'POST':
  55.         return do_the_login(request.form['username'], request.form['password'])
  56.     else:
  57.         return show_the_login_form()
  58.  
  59. @app.route('/hi/')
  60. @app.route('/hi/<name>') #go to the url and add these at the end.
  61. def hi(name=None):
  62.     return render_template('hello.html', name=name)
  63.  
  64.  
  65.  
  66.  
  67. @app.route('/derek') #go to the url and add these at the end.
  68. def derek():
  69.     return render_template('sample.html')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement