Skip to content
Sign upLog in
← Back to Community

Flask Tutorial How to Set it up!

Profile icon
Epicmuffinepic

Flask - How to set it up

When I wanted to make a website with python I know I wanted to use flask. But I didn't know how to set it up! This tutorial will get you set up for flask!

import flask

You could do this:

from flask import Flask, render_template

Or you could clear all the code (which I wouldn't do if you already have a lot of code) and Click the: examples and click the flask examples:

from flask import Flask app = Flask('app') @app.route('/') def hello_world(): return 'Hello, World!' app.run(host='0.0.0.0', port=8080)

The stuff on the top is basically setting up a screen for you.
That will put: Hello, World!
In the screen

But we want to connect to HTML

So bascially we have to put in imports:

from flask import Flask, render_template #Make sure to include the render_template or it won't work

Ok now we add the following code:

app = Flask('app') @app.route('/') def home(): return render_template('index.html') app.run(host='0.0.0.0', port=8080)

You can name the function(def home) what ever you want but I'm going to name it home because it is, like, the home page.

Next you are going to create a folder named templates. Make sure it is named templates or it won't work. Add a file in the folder called:

index.html

Then add anything you want to it! You can make multiple files in the single templates folder.

REMEBER THIS IS ONLY A BASIC TUTORIAL ON HOW TO SET UP! I BET THERE IS A LOT MORE DIFFERENT WAYS TO DO THIS!!

SIDE NOTE: IF IT DOES NOT WORK MAKE SURE YOU HAVE THE LAST LINE:

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

DOUBLE SIDE NOTE: If it still doesn't work then reload your page.

Voters
Profile icon
DanialOthman
Profile icon
JaspiDiceYT
Profile icon
EmeraldThunder
Profile icon
AmoghTheCool
Profile icon
wjnb
Profile icon
Epicmuffinepic
Comments
hotnewtop
Profile icon
EtonWilliams

Got it to work.
Had to look to see what code should be in the index.html file. First attempt had an empty file. Then I looked at your implementation and copied in the html code. Thank you for publishing this. Helped me to answer a challenge from a friend to implement a flask program be the end of the day - within a few minutes