반응형
저는 Python 및 Flask를 처음 사용하고 C #에서와 같이 Response.redirect
와 동일한 작업을 수행하려고합니다. 즉, 특정 URL로 리디렉션-어떻게해야합니까?
내 코드는 다음과 같습니다.
import os
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello World!'
if __name__ == '__main__':
# Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)
해결 방법
리디렉션을 반환해야합니다.
import os
from flask import Flask,redirect
app = Flask(__name__)
@app.route('/')
def hello():
return redirect("http://www.example.com", code=302)
if __name__ == '__main__':
# Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)
참조 페이지 https://stackoverflow.com/questions/14343812
반응형
'파이썬' 카테고리의 다른 글
파이썬 문자열을 datetime.time 객체로 변환 (0) | 2021.01.27 |
---|---|
파이썬 Python에서 정수 크기 가져 오기 (0) | 2021.01.27 |
파이썬 Is there any difference between "string" and 'string' in Python? (0) | 2021.01.27 |
파이썬 Reshape an array in NumPy (0) | 2021.01.27 |
파이썬 threading.Thread 객체에 '시작'이 있지만 '중지'가 아닌 이유는 무엇입니까? (0) | 2021.01.26 |
댓글