1from flask import Flask
2app = Flask(__name__)
3
4@app.route('/')
5def hello_world():
6 return 'Hello, World!'
7
1# This is a basic Flask Tutorial
2# First of all, if something doesn't work, you messed up.
3# Too start of, make a project folder and install flask with a venv or just normally.
4# You can install flask with this command: pip install Flask
5# (type this into you're terminal)
6# I f you get an error message, it is because you a, dont have python3 installed,
7# b: youre on a mac that has Python3 and python2 installed (this is probably the case)
8# If you dont have python3 installed then go ahead and install it. If it is case b, then type in
9# pip3 install Flask
10# Now, lets start by making a file named app.py
11# You can return basic html or text when returning in the
12# Hello World function. The @app.route('/') defines that the function
13# Will return at the page '/'. Debug mode is turned on on and the website
14# Will run at 0.0.0.0:5000 aka localhost:5000.
15
16from flask import Flask #Import Flask
17from flask import render_template #Import render template function
18app = Flask(__name__)
19
20
21@app.route('/')
22def hello_world():
23 return '''<h1>Welcome to Flask!</h1><a href=" /about">About Me!</a>'''
24
25
26# You can also return a Template. For that, make a Templates folder
27# and create a file named about.html inside of the Templates folder
28# html file contents (copy and paste it without the hashtags):
29
30#<html>
31# <body>
32# <h1>About Me</h1>
33# <p>Hi, this is me, I am a Python programmer who is currently learning Flask!</p>
34# <a href="/">Home</a>
35# </body>
36#</html>
37
38# (You can edit it if you want)
39
40#Just for you info, you your Project folder should look like this:
41# ProjectFolder:
42# app.py
43# Templates:
44# about.html
45# Lets make a site at localhost:5000/about and use the template we created
46
47
48@app.route('/about')
49def about():
50 return render_template("about.html") # You can do this with every html file in the templates folder
51
52#If you would like to have the same page with 2 diffrent urls (this works with as many as you want)
53#You can do this:
54@app.route('/page1')
55@app.route('/page2')
56def page1andpage2():
57 return 'Page1 and pag2 are now the same!'
58#ps: you dont have to name the function page1andpage2
59#you can name every function as you like. It doesn't matter.
60#The only thing that matters about the url is the decorator (@app.route('blabla'))
61#You can now acces this site on localhost:5000/page1 and on localhost:5000/page2 and they are both the same.
62
63#Since I dont want to make this "Grepper Tutorial" I am prabably going to make a 2cnd part if guys like this
64
65
66
67
68if __name__ == '__main__':
69 app.debug = True
70 app.run("0.0.0.0", 5000 , debug = True) #If you want to run youre website on a diffrent port,
71 #change this number ^
1from flask import Flask
2app = Flask('app')
3
4@app.route('/')
5def hello_world():
6 return 'Hello, World!'
7
8app.run(host='0.0.0.0', port=8080)
1Flask is a Python framework for web development.
2
3When creating simple static sites, there is no need to use backend frameworks.
4However, when creating complex and large sites that are backend heavy,
5you will want to use a backend framework. Currently, the 2 Python frameworks
6that are the most useful to learn are Flask and Django.
7
8Flask:
9Micro and light-weight framework that is easy to learn.
10
11Django:
12Complex, full-stack framework that is extremely powerful.
13
14For smaller projects, Flask will work. However, for large ones, you might
15consider learning Django. I suggest you learn Flask first and then Django.
16
17Additionally, considering learning Node JS because even though it is in
18Javascript, it is extremely popular.