Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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
 
PREVIOUS NEXT
Tagged: #python #basic #flask #web
ADD COMMENT
Topic
Name
1+6 =