Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

python flask

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
  return "Hello world!" #if you want to render a .html file, 
                        # import render_template from flask and use 
                        #render_template("index.html") here.

if __name__ == '__main__':
    app.debug = True
    app.run() #go to http://localhost:5000/ to view the page.
Comment

flask

# This is a basic Flask Tutorial
# First of all, if something doesn't work, you messed up.
# Too start of, make a project folder and install flask with a venv or just normally.
# You can install flask with this command: pip install Flask
# (type this into you're terminal)
# I f you get an error message, it is because you a, dont have python3 installed,
# b: youre on a mac that has Python3 and python2 installed (this is probably the case)
# If you dont have python3 installed then go ahead and install it. If it is case b, then type in
# pip3 install Flask
# Now, lets start by making a file named app.py
# You can return basic html or text when returning in the
# Hello World function. The @app.route('/') defines that the function
# Will return at the page '/'. Debug mode is turned on on and the website
# Will run at 0.0.0.0:5000 aka localhost:5000.

from flask import Flask #Import Flask
from flask import render_template #Import render template function
app = Flask(__name__)


@app.route('/')
def hello_world():
    return '''<h1>Welcome to Flask!</h1><a href=" /about">About Me!</a>'''


# You can also return a Template. For that, make a Templates folder
# and create a file named about.html inside of the Templates folder
# html file contents (copy and paste it without the hashtags):

#<html>
#   <body>
#       <h1>About Me</h1>
#       <p>Hi, this is me, I am a Python programmer who is currently learning Flask!</p>
#       <a href="/">Home</a>
#   </body>
#</html>

# (You can edit it if you want)

#Just for you info, you your Project folder should look like this:
#     ProjectFolder:
#       app.py
#       Templates:
#           about.html
# Lets make a site at localhost:5000/about and use the template we created


@app.route('/about')
def about():
    return render_template("about.html")  # You can do this with every html file in the templates folder

#If you would like to have the same page with 2 diffrent urls (this works with as many as you want)
#You can do this:
@app.route('/page1')
@app.route('/page2')
def page1andpage2():
    return 'Page1 and pag2 are now the same!'
#ps: you dont have to name the function page1andpage2
#you can name every function as you like. It doesn't matter.
#The only thing that matters about the url is the decorator (@app.route('blabla'))
#You can now acces this site on localhost:5000/page1 and on localhost:5000/page2 and they are both the same.

#Since I dont want to make this "Grepper Tutorial" I am prabably going to make a 2cnd part if guys like this




if __name__ == '__main__':
    app.debug = True
    app.run("0.0.0.0", 5000 , debug = True) #If you want to run youre website on a diffrent port,
    #change this number ^
Comment

flask

from flask import Flask
app = Flask('app')

@app.route('/')
def hello_world():
  return 'Hello, World!'

app.run(host='0.0.0.0', port=8080)
Comment

what is flask

These are by far the best Flask tutorials there are: https://youtube.com/playlist?list=PLzMcBGfZo4-n4vJJybUVV3Un_NFS5EOgX
Comment

what is flask

Flask is a web framework written in Python. 
This means flask provides you with tools, libraries and technologies that allow you to build a web application.

Here a a few resources for learning Flask (I have not personally used them before):
	https://youtube.com/playlist?list=PLzMcBGfZo4-n4vJJybUVV3Un_NFS5EOgX
    https://realpython.com/tutorials/flask/
    https://opensource.com/article/18/4/flask
Comment

flask

pip install flask
Comment

flask

$ flask run --host=0.0.0.0
Comment

flask

$ python3.6 -m venv --without-pip virtual
Comment

python flask

{% set fruit = 'apple' %}
{% set name, age = 'Tom', 20 %} {# tuple unpacking works inside templates too #}
Comment

flask

$ source virtual/bin/activate
Comment

flask

$ curl https://bootstrap.pypa.io/get-pip.py | python
Comment

python flask

<html>
    <head>
        <title>{{ title }}</title>
    </head>
    <body>
        <h1>Hello {{ username }}</h1>
    </body>
</html>
Comment

PREVIOUS NEXT
Code Example
Shell :: delete non empty directory cmd 
Shell :: What is the difference between git push origin and git push origin master 
Shell :: update ubuntu to gnome 40 
Shell :: install gnome-clocks ubuntu 
Shell :: install pytorch in jupyter notebook 
Shell :: conda install cython 
Shell :: how to setup wordpress in docker 
Shell :: git revert to commit 
Shell :: git remove last pushed commit 
Shell :: generating javadoc 
Shell :: ubuntu install libgcc.i686 
Shell :: su: failed to execute /bin/bash: Resource temporarily unavailable 
Shell :: docker logs 
Shell :: how to undo a local commit 
Shell :: windows ssh-copy-id 
Shell :: how to install mongoose globally 
Shell :: windows execute powershell script define user 
Shell :: ntfsfix ubantu 
Shell :: extract tar.gz in linux 
Shell :: create branch based to other branch ex. master 
Shell :: installing sdk manager on ubuntu 
Shell :: install tar files on linux 
Shell :: npm install xlsx 
Shell :: install aws cli version 2 on mac 
Shell :: git https to ssh 
Shell :: How to clear or delete Terminal history in linux 
Shell :: open port on firewall linux 
Shell :: error: src refspec develop does not match any 
Shell :: extract tar.gz 
Shell :: linux rename files add prefix 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =