๐ฉ๐ป ๋ฐฑ์๋(Back-End)/Node js
๋ค์ ๋์ .. Flask ๊ธฐ๋ณธ์ ์ธ ์น ํ์ด์ง ๊ตฌ์ถ (1)
์ง์ง์ํ์นด
2022. 11. 15. 14:44
728x90
๋ฐ์ํ
221115 ์์ฑ
<๋ณธ ๋ธ๋ก๊ทธ๋ wikidocs ์ ๋ธ๋ก๊ทธ๋ฅผ ์ฐธ๊ณ ํด์ ๊ณต๋ถํ๋ฉฐ ์์ฑํ์์ต๋๋ค :-)>
01-6 ํด๋ผ์ด์ธํธ์์ ์๋ฒ๋ก ๋ฐ์ดํฐ ๋ณด๋ด๊ธฐ1
# html์ formํ๊ทธ๋ฅผ ์์ฑ - post์ ๊ฒฝ์ฐ name์์ฑ์ ์๋ฒ์์ ์ฌ์ฉํ ๋ณ์๋ช ๋๋ ํค ๊ฐ์ด ๋ฉ๋๋ค. ```html Title …
wikidocs.net
๐ ํ๋ก์ ํธ์ฉ ํด๋ ์์ฑ
- pip install virtualenv
- virtualenv venv
๐ ๊ฐ์ํ๊ฒฝ ํ์ฑํ/๋นํ์ฑํ
- windows : venv\Scripts\activate
- mac, linux : source venv\bin\activate ๋๋ source venv\Scripts\activate
๐ ํ๋ผ์คํฌ ํจํค์ง ์ค์น
- pip3 install flask
๐ ๊ธฐ๋ณธ์ ์ธ ์นํ์ด์ง ๊ตฌ์ถ
- main.js
- ํ์ฌ ์์..
- style.css
h1{
color : blue;
}
- index.html
<!-- ํ์ํ html ํ์ผ์ ๋ชจ์๋ ์์ -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
<h1>์ด์์ Flask๋ ์ฒ์์ด์ง?</h1>
์ด๋ฆ : {{user}}
๋ ๋ฒจ : {{data.level}}
ํฌ์ธํธ : {{data.point}}
๊ฒฝํ์น : {{data.exp}}
</body>
</html>
- app.py
##### ์คํ์ ์๋ฒ๊ฐ ๊ฐ๋๋ ํ์ด์ฌ ํ์ผ #####
# app.py
from flask import Flask, render_template
#Flask ๊ฐ์ฒด ์ธ์คํด์ค ์์ฑ
app = Flask(__name__)
@app.route('/') # ์ ์ํ๋ url
# def index():
# return render_template('index.html')
def index():
return render_template('index.html',user="๋ฐ์",data={'level':60,'point':360,'exp':45000})
if __name__=="__main__":
app.run(debug=True)
# host ๋ฑ์ ์ง์ ์ง์ ํ๊ณ ์ถ๋ค๋ฉด
# app.run(host="127.0.0.1", port="5000", debug=True)
๐ ๊ฒฐ๊ณผ
728x90
๋ฐ์ํ