Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

simple flask app

# 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

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

PREVIOUS NEXT
Code Example
Python :: drop column of datfame 
Python :: django composite primary key 
Python :: extract a jar py 
Python :: sns histplot nan values 
Python :: get os info in python 
Python :: python round 1 decimal place 
Python :: remove vowels in a string python 
Python :: how to change int to string in python 
Python :: python how to get data from dictionary 
Python :: get mean using python 
Python :: python index of lowest value in list 
Python :: make parameter optional python 
Python :: best scraping package in python 
Python :: add horizontal line to plotly scatter 
Python :: isodate in python 
Python :: program to add first and last digit of a number in python 
Python :: python mann kendall test 
Python :: push in python 
Python :: matplotlib despine 
Python :: get reactions from message discord.py 
Python :: makemigration django 
Python :: python loc 
Python :: python removing duplicate item 
Python :: keras loss plot 
Python :: seaborn distribution plot for all columns 
Python :: permutation of a string in python 
Python :: python find index of closest value in list 
Python :: py one line function 
Python :: kdeplot python 
Python :: circular cropping of image in python 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =