인공지능, 머신러닝/Django + DataScience

[Django prac][weather graph] 3. 경로 설정

bay07 2024. 4. 5. 17:18

# 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 이상이어야한다.