Python flask 프레임 워 크 구현 브 라 우 저 사용자 정의 점프 페이지 클릭

코드 는 다음 과 같다.
_init_.py

from flask import Flask, request, url_for, redirect, render_template

app = Flask(__name__)

@app.route('/')
def index():
  return render_template('index.html')

@app.route('/cool_form', methods=['GET', 'POST'])
def cool_form():
  if request.method == 'POST':
    # do stuff when the form is submitted

    # redirect to end the POST handling
    # the redirect can be to the same route or somewhere else
    return redirect(url_for('index'))

  # show the form, it wasn't submitted
  return render_template('cool_form.html')
index.html

<!doctype html>
<html>
<body>
  <p><a href="{{ url_for('cool_form') }}" rel="external nofollow" >Check out this cool form!</a></p>
</body>
</html>
cool_form.html

<!doctype html>
<html>
<body>
  <form method="post">
    <button type="submit">Do it!</button>
  </form>
</html>
실행 결과

5000 포트 에 들 어가 면 그림 과 같이 이 단 추 를 누 르 고 사용자 정의/cool 로 이동 합 니 다.form 페이지

코드 가 github:https://github.com/qingnvsue/flask에 있 는 웹 button 폴 더
내 프로그램 에서 나 는 웹 페이지 에서 덧셈 기 나 나눗셈 기 단 추 를 누 르 면 해당 페이지 에 들 어 가 는 것 을 실현 했다.



코드 가 github:https://github.com/qingnvsue/flask에 있 는 add 폴 더
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기