Advertisement
lessientelrunya

FlaskURLfor

Apr 14th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. >>> from flask import Flask, url_for
  2. >>> app = Flask(__name__)
  3. >>> @app.route('/')
  4. ... def index(): pass
  5. ...
  6. >>> @app.route('/login')
  7. ... def login(): pass
  8. ...
  9. >>> @app.route('/user/<username>')
  10. ... def profile(username): pass
  11. ...
  12. >>> with app.test_request_context():
  13. ...  print url_for('index')
  14. ...  print url_for('login')
  15. ...  print url_for('login', next='/')
  16. ...  print url_for('profile', username='John Doe')
  17. ...
  18.  
  19. # /
  20. # /login
  21. # /login?next=/
  22. # /user/John%20Doe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement