Computer Programming/AI

TIL_Python

JYCoder 2023. 8. 8. 20:25

사전캠프 없이 프로그램에 바로 참여했기 때문에 어제와 오늘은 강의 듣기로 바쁘다.

 

folder 생성 => app.py file 만들기 => git bash terminal에서 'python -m venv venv'를 입력하여 라이브러리들을 넣을 venv(가상환경)라는 folder를 생성 => Python 3.10.4('venv':venv)로 잡아주기 => 'pip install flask' => 

flask 시작 코드

from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
   return 'This is Home!'

if __name__ == '__main__':  
   app.run('0.0.0.0',port=5000,debug=True)

=> Run Python file in Terminal => 브라우저에서 'localhost:5000' 

 

*mongoDB를 사용하고 싶다면,

pip install pymongo

pip install dnspython

 

index.html 뼈대 코드

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <title>Document</title>

    <script>
        function hey(){
            alert('안녕!')
        }
    </script>
</head>
<body>
    <button onclick="hey()">나는 버튼!</button>
</body>
</html>
LIST