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

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

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

PREVIOUS NEXT
Code Example
Python :: reverse one hot encoding python numpy 
Python :: python loop through files in directory 
Python :: sns scatter plot 
Python :: how to put iput python 
Python :: start the environment 
Python :: how to print items in a list in a single line python 
Python :: how to make a bot say hello <username when a user says hello in discord with python 
Python :: make python file executable linux 
Python :: python volver al principio 
Python :: decyphing vigener cypher without key 
Python :: insert QlineEdit into QMenu python 
Python :: python: separate lines including the period or excalamtion mark and print it to the prompt.. 
Python :: how to shutdown your computer using python 
Python :: django create app 
Python :: printing hollow triangle in python 
Python :: add year to id django 
Python :: place a widget in tkinter 
Python :: hotel room allocation tool in python 
Python :: wap to draw the shape of hexagonn in python 
Python :: python extract all numbers from string re 
Python :: pandas decimal places 
Python :: date format in django template 
Python :: get text from image python 
Python :: truncate add weird symbols in python 
Python :: df select first n rows 
Python :: how to strip a list in python 
Python :: file path current directory python 
Python :: Jupyter notebook: let a user inputs a drawing 
Python :: ValueError: There may be at most 1 Subject headers in a message 
Python :: ValueError: logits and labels must have the same shape ((None, 1) vs (None, 2)) 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =