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)
# 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()
# 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.
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()
#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)
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
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == '__main__':
app.run()
# 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