Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- ํ ์ด๋ธ
- ๋ฆฌ๋ ์ค
- ์๋ฐ์คํฌ๋ฆฝํธ
- ๋ฐฑํฑ
- ์ปจํธ๋กค๋ฌ
- ์ธ๋ผ์ธ๋ทฐ
- ๋ช ๋ น์ด
- JavaScript
- Spring
- post๋ฐฉ์
- optionํ๊ทธ
- MySQL
- ๋ฐฐ์ด
- ๋์
- Update
- SQL
- like
- oracle
- select
- JSP
- Ajax
- JS
- ๋ณ์
- ๋์ปค
- order by
- ์ฝํ
- ํ๋ก๊ทธ๋๋จธ์ค
- DATE_FORMAT
- ๋์ ํ ์ด๋ธ
- ํจ์
Archives
- Today
- Total
bom's happy life
app.py / index.html ๋ผ๋์ฝ๋ ๋ณธ๋ฌธ
๋ผ๋์ฝ๋๋ก ์ฌ์ฉํ๋ฉด ๋๋ค.
[์ฝ๋๋์คํซ]
ํฌ๋ช ๋กapp.py
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route("/homework", methods=["POST"])
def homework_post():
sample_receive = request.form['sample_give']
print(sample_receive)
return jsonify({'msg':'POST ์ฐ๊ฒฐ ์๋ฃ!'})
@app.route("/homework", methods=["GET"])
def homework_get():
return jsonify({'msg':'GET ์ฐ๊ฒฐ ์๋ฃ!'})
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)
ํฌ๋ช ๋กindex.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<title>์ด๋ฏธ๋ํํผ - ํฌ๋ช
๋ก</title>
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif+KR:wght@200;300;400;500;600;700;900&display=swap" rel="stylesheet">
<style>
* {
font-family: 'Noto Serif KR', serif;
}
.mypic {
width: 100%;
height: 300px;
background-image: linear-gradient(0deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('์ํฐ์คํธ ์ฌ์งURL');
background-position: center 30%;
background-size: cover;
color: white;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.mypost {
width: 95%;
max-width: 500px;
margin: 20px auto 20px auto;
box-shadow: 0px 0px 3px 0px black;
padding: 20px;
}
.mypost > button {
margin-top: 15px;
}
.mycards {
width: 95%;
max-width: 500px;
margin: auto;
}
.mycards > .card {
margin-top: 10px;
margin-bottom: 10px;
}
</style>
<script>
$(document).ready(function(){
set_temp()
show_comment()
});
function set_temp(){
$.ajax({
type: "GET",
url: "http://spartacodingclub.shop/sparta_api/weather/seoul",
data: {},
success: function (response) {
$('#temp').text(response['temp'])
}
})
}
function save_comment(){
$.ajax({
type: 'POST',
url: '/homework',
data: {sample_give:'๋ฐ์ดํฐ์ ์ก'},
success: function (response) {
alert(response['msg'])
window.location.reload()
}
})
}
function show_comment(){
$.ajax({
type: "GET",
url: "/homework",
data: {},
success: function (response) {
alert(response["msg"])
}
});
}
</script>
</head>
<body>
<div class="mypic">
<h1>์ํฐ์คํธ์ด๋ฆ ํฌ๋ช
๋ก</h1>
<p>ํ์ฌ๊ธฐ์จ: <span id="temp">36</span>๋</p>
</div>
<div class="mypost">
<div class="form-floating mb-3">
<input type="text" class="form-control" id="name" placeholder="url">
<label for="floatingInput">๋๋ค์</label>
</div>
<div class="form-floating">
<textarea class="form-control" placeholder="Leave a comment here" id="comment"
style="height: 100px"></textarea>
<label for="floatingTextarea2">์์๋๊ธ</label>
</div>
<button onclick="save_comment()" type="button" class="btn btn-dark">์์ ๋จ๊ธฐ๊ธฐ</button>
</div>
<div class="mycards" id="comment-list">
<div class="card">
<div class="card-body">
<blockquote class="blockquote mb-0">
<p>์๋ก์ด ์จ๋ฒ ๋๋ฌด ๋ฉ์ ธ์!</p>
<footer class="blockquote-footer">ํธ๋นต๋งจ</footer>
</blockquote>
</div>
</div>
<div class="card">
<div class="card-body">
<blockquote class="blockquote mb-0">
<p>์๋ก์ด ์จ๋ฒ ๋๋ฌด ๋ฉ์ ธ์!</p>
<footer class="blockquote-footer">ํธ๋นต๋งจ</footer>
</blockquote>
</div>
</div>
<div class="card">
<div class="card-body">
<blockquote class="blockquote mb-0">
<p>์๋ก์ด ์จ๋ฒ ๋๋ฌด ๋ฉ์ ธ์!</p>
<footer class="blockquote-footer">ํธ๋นต๋งจ</footer>
</blockquote>
</div>
</div>
</div>
</body>
</html>
์ด์ ์ฌ๊ธฐ์
์์๋จ๊ธฐ๊ธฐ(post๋ฐฉ์)๊ณผ
์์๋ณด๊ธฐ(get๋ฐฉ์)์ ์ฐ์ตํด๋ณด์.
์์ฐธ! ์ง๊ธ localhost:5000 ์ฃผ์๋ ์ํ๊ธฐ๋กํ๊ธฐ ์ฃผ์๋ก ๋์ด์๋ค.
ํฌ๋ช ๋ก ์ฃผ์๋ localhost:5000์ด๋ผ๋๋ฐ ๋๋ ์ฌ์ ํ ์ํ๊ธฐ๋กํ๊ธฐ์ฐฝ์ผ๋ก ๋ฌ๋ค,
์ด๋ด๋๋ ์ด๋ป๊ฒ ํด์ผํ ๊น?
์ ์๋์ ์ฝ๋ฉํธ^^!!
์นํ์ด์ง๋ฅผ ์คํํ๊ธฐ ์ ์ ์๋ฒ๋ฅผ ๋จผ์ ์คํํ๊ฒ ๋์ด์์ฃ ?
๊น๋ด๋์ ์นํ์ด์ง์ ๋ํ ๋ฐ์ดํฐ๋ฅผ ๋ณด๋ด์ฃผ๋ ์๋ฒ๊ฐ localhost:5000 ์ด๋ผ๋ API๋ฅผ ํตํด ๋ฐ์ดํฐ๋ค์ ์ ๋ฌํด์ฃผ๊ณ ์๋ ๊ฒ์ด์ฃ ^^๊ฐ๊ฐ์ ํ์ด์ง๋ฅผ ๋ง๋ค ๋๋ง๋ค ๊ฐ๊ฐ ๋ค๋ฅธ ์๋ฒ๋ฅผ ๋ง๋ค์ด ์ฃผ๊ณ ์๋ ์ด์ ์ ๋๋ค^^
์ด๋ค ์๋ฒ๋ฅผ ์ผ๋์๋๋์ ๋ฐ๋ผ ๊ฐ์ ์ฃผ์์๋ ๋ค๋ฅธ ๋ฐ์์ด ์ค๊ฒ ๋ฉ๋๋ค^^localhost:5000๋ฅผ ์ ๋ ฅํ์ จ์ ๋
์ํ๊ธฐ๋กํ๊ธฐ ์ฌ์ดํธ๊ฐ ๋จ๊ฒ ๋๋ค๋ฉด ํ์ฌ ๊ทธ ์๋ฒ๊ฐ ๋์๊ฐ๊ณ ์๊ธฐ ๋๋ฌธ์ ๋๋ค^^
** ๊ทธ๋์ ์๋ก์ด ํ๋ก์ ํธ๋ฅผ ์์ํ ๋๋ ๊ธฐ์กด ํ๋ก์ ํธ๋ฅผ ๋ซ์์ฃผ๋ ๊ฒ์ด ์ข๊ฒ ๋ค!!
'Deveolpment Study๐๏ธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๊ธฐ๋ณธ ์ด๋ก ๋ณต์ต (0) | 2022.06.29 |
---|---|
ํ์ด์ฐธ์์ ์ ํ๋ก์ ํธ ์์ฑํ๋ ๋ฒ (0) | 2022.06.29 |
POST์ GET์ฐ์ตํ๊ธฐ(์ํ๊ธฐ๋กํ๊ธฐ) - ์คํ๋ฅดํ 14๊ฐ (0) | 2022.06.16 |
[์น ๊ฐ๋ฐ 2 ์ฃผ์ฐจ] ๊ฐ๋ฐ์ผ์ง 7 - ๋จ์ถํค์ ์์ ๋ชฉํ (0) | 2022.05.25 |
[์น ๊ฐ๋ฐ 1 ์ฃผ์ฐจ] ๊ฐ๋ฐ์ผ์ง 3 - ํฌ์คํ ๋ฐ์ค ๋ง๋ค๊ธฐ ์ค์ต (0) | 2022.05.23 |