Download our e-book of Introduction To Python
Vishal Mane
3 years ago
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello InsideAIML'
if __name__ == '__main__':
app.run()
* Serving Flask app "flask_route" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [06/Aug/2018 08:48:45] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [06/Aug/2018 08:48:46] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [06/Aug/2018 08:48:46] "GET /favicon.ico HTTP/1.1" 404 -
Hello InsideAIML
from flask import Flask, url_for
app = Flask(__name__)
@app.route('/')
def index(): pass
@app.route('/login')
def login(): pass
@app.route('/user/')
def profile(username): pass
with app.test_request_context():
print url_for('index')
print url_for('index', _external=True)
print url_for('login')
print url_for('login', next='/')
print url_for('profile', username='InsideAIML')
/
http://localhost/
/login
/login?next=%2F
/user/InsideAIML
from flask import Flask, abort, redirect, url_for
app = Flask(__name__)
@app.route('/')
def index():
return redirect(url_for('login'))
@app.route('/login')
def login():
abort(401)
# this_is_never_executed()