Skip to content

Instantly share code, notes, and snippets.

@santosh
Created November 2, 2017 07:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save santosh/ec153ae4dca7099b5935af5c94e631e0 to your computer and use it in GitHub Desktop.
Save santosh/ec153ae4dca7099b5935af5c94e631e0 to your computer and use it in GitHub Desktop.
Return back user agent in Flask. #Python
from flask import Flask, request
app = Flask(__name__)
@app.route('/')
def index():
user_agent = request.headers.get('User-Agent')
return '<p>Your browser is {}!</p>'.format(user_agent)
@app.route('/user/<name>')
def user(name):
return '<h1>Hello, {name}!</h1>'.format(name=name)
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment