Skip to main content

Command Palette

Search for a command to run...

Basic of Flask

Published
1 min readView as Markdown

When you create Flask server, make sure to have three items in the project folder.

  1. Static folder ; Usually, image or CSS files will be stored
  2. Templates folder ; HTML files will be stored
  3. App.py file
  • Create directory folders named 'templates' and 'static' respectively. image.png

Start with the code below.

from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
   return 'This is Home!'

if __name__ == '__main__':
   app.run('0.0.0.0',port=5000,debug=True)

  • Update the code like below and open http://localhost:5000/
from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
   return '<button>나는 버튼이다</button>'

if __name__ == '__main__':
   app.run('0.0.0.0',port=5000,debug=True)

image.png

  • Create a HTML file named index.html under templates folder.

  • write a code like below in index.html file.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
  <h1>나의 첫 웹페이지!</h1>
  <button>버튼을 만들자</button>
</body>
</html>
  • write a code in app.py file
from flask import Flask, render_template
app = Flask(__name__)

@app.route('/')
def home():
   return render_template('index.html')

if __name__ == '__main__':
   app.run('0.0.0.0',port=5000,debug=True)

image.png

it reads and show the HTML file we made. So if you have HTML file and it can be uploaded online in this way!

More from this blog

Ollie Seongyong Kim

85 posts