
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
코드에 문제가 있나요?
이 페이지를 볼 수 있는 권한이 없습니다.HTTP ERROR 403
이렇게 떠서요..
from flask import Flask, render_template
import random
app = Flask(__name__)
@app.route('/')
def home():
name = '김서연'
lotto = [16, 18, 22, 43, 32, 11]
def generate_lotto_numbers():
numbers =random.sample(range(1, 46), 6)
return sorted(numbers)
random_lotto = generate_lotto_numbers()
def count_common_elements(list1, list2):
common_elements = set(list1) & set(list2)
return len(common_elements)
common_count = count_common_elements(lotto, random_lotto)
context = {
"name": name,
"lotto": lotto,
"random_lotto": random_lotto,
'common_count': common_count
}
return render_template('index.html', data=context)
@app.route('/mypage')
def mypage():
return 'This is mypage!'
if __name__ == '__main__':
app.run(debug=True)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1>안녕, {{data.name}}</h1>
<h2>로또 번호: {{data.lotto}}</h2>
<h2>랜덤 로또 번호: {{data.random_lotto}}</h2>
<!-- 당첨 갯수에 따라 메시지 표시 -->
{% if data.common_count == 6 %}
<h2>{{data.common_count}}개 맞았습니다. 1등입니다.</h2>
{% if data.common_count == 5 %}
<h2>{{data.common_count}}개 맞았습니다. 2등입니다.</h2>
{% if data.common_count == 4 %}
<h2>{{data.common_count}}개 맞았습니다. 3등입니다.</h2>
{% if data.common_count == 3 %}
<h2>{{data.common_count}}개 맞았습니다. 4등입니다.</h2>
{% else %}
<h2>{{data.common_count}}개 맞았습니다. 탈락입니다.</h2>
{% endif %}
</body>
</html>
