Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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 page

from flask import Flask		# Imports flask
app = Flask(__name__)		# Setting up the app

@app.route('/')				# Sets the route for the page
def hello_world():			
    return 'Hello, World!'	# Returns 'Hello, World' wheen
							# you go to the '/' or main page
Comment

PREVIOUS NEXT
Code Example
Python :: python all 
Python :: how to create templates in python 
Python :: what is variance in machine learning 
Python :: nested dictionary python 
Python :: numpy array into tuple 
Python :: django form date picker 
Python :: import from parent directory in python setup 
Python :: create anaconda env 
Python :: python max of two numbers 
Python :: sorting in python 
Python :: Sys Gets os name ,which u using 
Python :: np.random.rand() 
Python :: Python format() function uses. 
Python :: tkinter hide legend 
Python :: icloud api python 
Python :: copy something character ubntil a specific character in python 
Python :: multiprocessing write to dict 
Python :: wrds in python 
Python :: Paraphrasing text with transformers library 
Python :: len list python 
Python :: pandascheck if two columns match and populate new column 
Python :: tz convert python 
Python :: remove color from shapefile python 
Python :: pip_install_packages2.bat 
Python :: sklearn mahalanobis distance 
Python :: auto clipping path when upload image using python 
Python :: python no module named encodings 
Python :: bulk upload with dictionary or list in django moels 
Python :: python get function from string name 
Python :: python default parameters depend on other paramters 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =