# myapps > templates
templates 폴더 만들기
index.html 생성
<!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>메인페이지</h1>
</body>
</html>
# myapps > views.py
from django.shortcuts import render
import matplotlib.pyplot as plt
def index(request):
x = [1, 2, 3, 4]
y = [2, 4, 6, 8]
plt.plot(x,y)
plt.title("test graph")
plt.xlabel('x label')
plt.ylabel('y label')
plt.show()
return render(request, "index.html")
# 서버 실행해서 결과 확인
save all
python manage.py runserver
http://127.0.0.1:8000/myapps
만약에, 서버 실행이 안되면 python interpreter를 바꿔보기
파이썬 버전이 3.9 이상이어야한다.
'인공지능, 머신러닝 > Django + DataScience' 카테고리의 다른 글
[Django prac][weather graph] 6. 메인페이지 (0) | 2024.04.05 |
---|---|
[Django prac][weather graph] 5. 날씨 데이터 가져오기 (0) | 2024.04.05 |
[Django prac][weather graph] 4. View에서 Template으로 이미지 전달하기 (0) | 2024.04.05 |
[Django prac][weather graph] 2. 경로 설정 (0) | 2024.04.05 |
[Django prac][weather graph] 0. 전체적인 흐름 (0) | 2024.04.05 |