ssh -i kt.pem ubuntu@00.00.000.00
ubuntu $ sudo apt-get install nginx
ubuntu $ sudo systemctl status nginx
sudo apt install tree
ubuntu $ sudo vi /etc/nginx/sites-available/default
- 이러한 화면이 뜸
- G 입력으로 가장 밑으로 감
- 아래 정적파일 설정 입력
정적파일 설정
server { listen 8080; location / { root /home/ubuntu/web; } }
- :wq
sudo systemct1 restart nginx
chmod +x /home/ubuntu
ubuntu $ sudo systemctl restart nginx
tmux new -s ai
# 함수 생성
def func1():
print('code1')
print('code2')
print('code3')
def func2():
print('code4')
print('code5')
print('code6')
func1
func2
>
code1
code2
code3
code4
code5
code6
# decorator 함수 생성
def deco(func):
def wrapper(*args, **kwargs):
print('code1')
func(*args, **kwargs)
print('code3')
return wrapper
# decorator 함수 사용
@deco
def func1():
print('code2')
@deco
def func2():
print('code4')
func1
func2
>
code1
code2
code3
code1
code4
code3
import time
# 코드가 출력되는데 걸리는 시간
start = time.time()
print('code')
end = time.time()
print(end - start)
>
code
0.0015552043914794922
# decorator 함수 생성
def show_time(func):
def wrapper():
start = time.time()
func()
end= time.time()
print(end - start)
return wrapper
# decorator 함수 사용
@show_time
def func1():
print('code2')
fuc1 = show_time(func1)
@show_time
def func2():
print('code4')
func1()
func2()
>
code2
0.002538442611694336
code4
# decorator 함수 생성
def login(func):
def wrapper():
pw = input('pw: ')
if kwargs['pw'] == '1234':
func()
else:
print('wrong password')
return wrapper
# decorator 함수 사용
@login
def fuc1()
print('code2')
func1()
>
pw 입력창에 1234 입력시
code2가 출력 된다.
def (n1, n2, n3):
print(n1 + n2 + n3)
plus(1, 2, 3)
>
6
# args
def (*args): # parameter 1개
print(type(args), args)
print(sum(args))
plus(1, 2, 3) # args 3개
>
<class 'tuple'> (1, 2, 3)
6
# kwargs
def (*args, **kwargs): # parameter 1개
print(type(args), args)
print(type(kwargs), kwargs)
print(sum(args) + kwargs.values())
plus(1, 2, 3, n4=10, n5=20) # args 3개
>
<class 'tuple'> (1, 2, 3)
<class 'dict'> {'n4': 10, 'n5': 20}
36
def echo(*args, **kwargs):
print(type(args), args)
print(type(kwargs), kwargs)
# args
data1 = [1, 2, 3]
echo(data1) # echo([1, 2, 3])
echo(*data1) # echo(1, 2, 3)
>
<class 'tuple'> ([1, 2, 3],)
<class 'dict'> {}
<class 'tuple'> (1, 2, 3)
<class 'dict'> {}
# kwargs
data2 = {'n4': 10, 'n5': 20}
echo(data2) # echo({'n4': 10, 'n5': 20})
echo(**data2) # echo(n4=10, n5=20)
# 디렉토리 생성
!mkdir -p hello/staic
!mkdir -p hello/templates
# 파일 생성
!touch hello/hello.py
!touch hello/templates/index.html
!tree hello

%%writefile helle/hello.py
from flask import *
app = Flask(__name__)
# 라우팅 코드
@app.route('/')
def hello():
return 'Hello Flask'
# 라우팅 코드를 요청했을때, index.html을 불러옴
@app.route('/user')
def user():
return render_template('index.html') # 랜더링을 통해 연결함
app.run(debug=True)
# 실행 되는지 확인
!cat hello/hello.py

server {
listen 8081;
location / {
proxy_pass http://localhost:5000;
}
}
%%writefile hello/templates/index.html
<!DOCTYPE>
<html>
<head>
<title>Flask</title>
</head>
<body>
<p>Hello Flask!!!</p><hr>
</body>
</html>