Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python flask sample application

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

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

python basic flask web

from flask import Flask

app = Flask(__name__)
#__name__ is passed as the paremater
@app.route('/')
#when the home page is open 
#e.g https://yourwebsite/
def home():
  return "Text in website"
@app.route('/about/')
#when the about page is open
#https://yourwebsite/about/
def about():
  return "About Text"
#when running your file the file name is __main__
#whatever you name it
#but when importing the file the name will be the name you named it
#so to run this file without importing we passed in the paremater __name__ 
#which is equal to __main__
#so we have to make sure it runs only from this file
if __name__ == "__main__":
  app.run()
#open your browser and write 
#127.0.0.1:5000
#to open your website
#you can change the host by passing in the host as an str
#in the app.run()
#e.g app.run("host")
#and you can also change the port
#e.g app.run("host",8464)
#this will open on host:8464
Comment

flask tutorial

from flask import Flask
app = Flask(__name__)

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

if __name__ == '__main__':
    app.run()
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 basics flask project

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
@app.route('/index')
@app.route('/home')
def index():
	return render_template('index.html')

# this is so the app won't run if the file is imported somewhere, run using a different methed, etc.
if __name__ == '__main__':
	app.run('127.0.0.1', port=8080, debug=True)  # 127.0.0.1 is the IP adress for localhost. You could also use 'localhost'
Comment

PREVIOUS NEXT
Code Example
Python :: confusion matrix with labels sklearn 
Python :: python compute cross product 
Python :: Modify a Python interpreter 
Python :: how to delete item from list python 
Python :: python map() 
Python :: batch gradient descent python 
Python :: django dumpdata specific app 
Python :: how to get SITE_ID in django....shell 
Python :: convert 2 level nested list to one level list in python 
Python :: Yahoo! Finance pyhton 
Python :: tqdm description 
Python :: know the type of variable in python 
Python :: extract outliers from boxplot 
Python :: os.startfile 
Python :: Reason: Worker failed to boot 
Python :: check multiple keys in python dict 
Python :: cv2 cuda support print 
Python :: python call function in class 
Python :: format dictionary python 
Python :: python dictionary pop key 
Python :: input for competitive programming 
Python :: Python | Pandas DataFrame.where() 
Python :: how to change values in dataframe python 
Python :: python convert 
Python :: python built in functions 
Python :: pandas replace values 
Python :: python slicing 
Python :: argparse print help if no arguments 
Python :: is python a programming language 
Python :: separate words in a text to make a list python 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =