Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

flask app example

# Extremely simple flask application, will display 'Hello World!' on the screen when you run it
# Access it by running it, then going to whatever port its running on (It'll say which port it's running on).
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run()
Comment

python basic flask app

# Imports necessary libraries
from flask import Flask 
# Define the app
app = Flask(__name__)

# Get a welcoming message once you start the server.
@app.route('/')
def home():
    return 'Home sweet home!'

# If the file is run directly,start the app.
if __name__ == '__main__':
    app.run(Debug=True)

# To execute, run the file. Then go to 127.0.0.1:5000 in your browser and look at a welcoming message.
Comment

flask app example

import flask

# A simple Flask App which takes
# a user's name as input and responds
# with "Hello {name}!"

app = flask.Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def index():
    message = ''
    if flask.request.method == 'POST':
        message = 'Hello ' + flask.request.form['name-input'] + '!'
    return flask.render_template('index.html', message=message)

if __name__ == '__main__':
    app.run()
Comment

basic flask app python

#Import Flask, if not then install and import.

import os
try:
  from flask import *
except:
  os.system("pip3 install flask")
  from flask import *

app = Flask(__name__)

@app.route("/")
def index():
  return "<h1>Hello World</h1>"

if __name__ == "__main__":
  app.run(host="0.0.0.0", port=8080, debug=False)
Comment

Create a Flask App

# save this as app.py
from flask import Flask, escape, request

app = Flask(__name__)

@app.route('/')
def hello():
    name = request.args.get("name", "World")
    return f'Hello, {escape(name)}!'
  
  # twitter : @MasudSha_
  # @MasudShah
Comment

python and flask create_app

>>> from yourapp import create_app
>>> app = create_app()
>>> app.app_context().push()
Comment

PREVIOUS NEXT
Code Example
Python :: python dictionary with dot notation 
Python :: python remove white space 
Python :: pandas merge sort columns 
Python :: fillna string 
Python :: how to define number in python 
Python :: time in python 
Python :: numpy unique axis 
Python :: extract decimal number from string python 
Python :: #Function in python 
Python :: how to count the number of guesses in python 
Python :: python cron job virtualenv 
Python :: csrf token django 
Python :: customise the django rest api view 
Python :: python different types of loops 
Python :: change every element of list python with map 
Python :: uninstall python ubuntu 18.04 
Python :: pip install 
Python :: dataclass in python 
Python :: pandas convert string to float 
Python :: insert function in list 
Python :: python linter online 
Python :: how to get csv file first row first column value in python 
Python :: generate table python 
Python :: how to save plot in matplotlib 
Python :: convert word to pdf python 
Python :: pandas switch column levels 
Python :: convert rgb image to binary in pillow 
Python :: correlation with target variable python 
Python :: save variable to use in other jupyter notebook 
Python :: looping over lists in python 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =