-2026 05 20-
ssh: jeonjucom.kr 22075
web: http://jeonjucom.kr:8075
ftp: jeonjucom.kr 21075
web은 집에서도 접속 가능

/home/master/projects/flask/templetes에서 웹 페이지를 기본적으로 수정 가능

flask로 만든 웹에 살 붙히기

login.html을 만들어 주고
app.py에서 로그인을 누르면 login.html으로 연결되게 설정.
apache2를 재시작 후 확인
login을 눌렀더니 Internal server error가 뜨면서 페이지가 보이지 않는다.
파일을 읽을 권한이 없기 때문
login.html의 권한을 644로 변경
다시 로딩해보면 정상적으로 login.html의 페이지가 보인다.
이런식으로 다른 페이지도 추가해주면 된다.

login.html에 아래코드 추가
<div class="container-fluid">
로그인<br>
<hr>
<form action="/action_page.php">
<div class="mb-3 mt-3">
<label for="email" class="form-label">Email:</label>
<input type="email" class="form-control" id="email" placeholder="Enter email" name="email">
</div>
<div class="mb-3">
<label for="pwd" class="form-label">Password:</label>
<input type="password" class="form-control" id="pwd" placeholder="Enter password" name="pswd">
</div>
<div class="form-check mb-3">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" name="remember"> Remember me
</label>
</div>
<button type="submit" class="btn btn-primary">로그인</button>
</form>
</div>


웹이 제대로 동작하지 않을 떄 에러를 확인하고 싶으면?
sudo tail -f /var/log/apache2/error.log

Flask에서 로그인 과정을 구현하려면?
1. 전송방식이해
GET
action_page.php?email=master%40aaa.com&pswd=123456

POST
action_page.php

Get방식인지 Post방식인지 먼저 확인.
ID와 Password를 보내려면 Post방식으로 보내야 한다.
왜? Get방식은 링크에서 표현이 되지만 Post방식은 링크에 보이지 않기때문.

초음파 모니터링 데이터를 받아와서 적용 시켜보자
app.py에서 데이터 받아올 곳을 em.izerone.co.kr로 바꿔준다.

제대로 적용이 된다면 웹에서 초음파 감지 데이터가 정상적으로 출력이 된다.

이제 모든 코드작업은 app.py에서 해주면 된다.

미션! 초음파가 176이상이라면 빨잔줄로 표시해보자.
Ai를 갈구면서 작업
기존에 있던 index.html을 아래와 같이 바꿔주자.
{% extends 'base.html' %}
{% block content %}
<style>

*{
margin:0;
padding:0;
box-sizing:border-box;
font-family:'Segoe UI', sans-serif;
}

body{
background:#f4f7fb;
#padding:40px;
}

.container{
max-width:1000px;
margin:auto;
}

.title{
font-size:32px;
font-weight:bold;
margin-bottom:25px;
color:#222;
}

.card{
background:white;
border-radius:20px;
padding:25px;
box-shadow:0 10px 30px rgba(0,0,0,0.08);
}

table{
width:100%;
border-collapse:collapse;
overflow:hidden;
border-radius:15px;
}

thead{
background:linear-gradient(135deg,#4facfe,#00f2fe);
color:white;
}

thead th{
padding:18px;
text-align:left;
font-size:15px;
}

tbody tr{
transition:0.2s;
border-bottom:1px solid #eee;
}

tbody tr:hover{
background:#f1f7ff;
transform:scale(1.01);
}

/* 측정 거리가 175 이하일 때 적용할 스타일 */
tbody tr.danger-row {
background-color: #ffebee; /* 연한 빨간색 배경 */
}

/* 마우스 올렸을 때도 빨간색 톤이 유지되도록 처리 */
tbody tr.danger-row:hover {
background-color: #ffcdd2;
}

/* 글자색도 강조하고 싶다면 추가 */
tbody tr.danger-row td,
tbody tr.danger-row .distance {
color: #c62828 !important; /* 짙은 빨간색 글자 */
}

tbody td{
padding:18px;
color:#444;
font-size:15px;
}

.badge{
display:inline-block;
padding:6px 12px;
border-radius:30px;
font-size:13px;
font-weight:bold;
background:#e3f2fd;
color:#1976d2;
}

.distance{
font-weight:bold;
color:#ff5722;
}

.time{
color:#888;
font-size:13px;
}

@media(max-width:768px){

body{
padding:15px;
}

.title{
font-size:24px;
}

table{
font-size:13px;
}

thead{
display:none;
}

table, tbody, tr, td{
display:block;
width:100%;
}

tr{
margin-bottom:15px;
background:white;
border-radius:15px;
padding:10px;
}

td{
text-align:right;
padding-left:50%;
position:relative;
}

td::before{
position:absolute;
left:15px;
top:15px;
font-weight:bold;
color:#333;
}

td:nth-child(1)::before{content:"번호";}
td:nth-child(2)::before{content:"센서";}
td:nth-child(3)::before{content:"거리";}
td:nth-child(4)::before{content:"시간";}
}

</style>
<script>
setTimeout(() => {
location.reload();
}, 3000);
</script>

<div class="container-fluid">
<h1 class="mt-4"></h1>
<p>데이터베이스에 저장된 내용을 출력합니다.</p>
<p>
<div class="title">
📡 초음파 센서 실시간 모니터링
</div>

<div class="card">

<table>

<thead>
<tr>
<th>#</th>
<th>센서 종류</th>
<th>측정 거리</th>
<th>측정 시간</th>
</tr>
</thead>

<tbody>

{% for row in datas %}

<tr {% if row.data | float >= 176 %}class="danger-row"{% endif %}>
<td>{{ row.idx }}</td>

<td>
<span class="badge">
{{ row.part }}
</span>
</td>

<td>
<span class="distance">
{{ row.data }} cm
</span>
</td>

<td class="time">
{{ row.reg_date }}
</td>
</tr>

{% endfor %}

</tbody>

</table>
</p>
</div>
</div>
</div>
{% endblock %}

바꿔준 html을 적용시켜주면
들어온 데이터중 176이 넘는 데이터는 배경이 빨갛게 표시된다.