2017-02-10 1 views
0

플라스크에 '글로벌 GET 관리'방법이 있습니까?플라스크의 글로벌 GET 관리

예 : 내 플라스크 응용 프로그램의 모든 페이지에서 popover를 통해 오류 메시지를 표시하려고합니다. 사용자가 '닫기'버튼을 클릭하면 응용 프로그램은 새로운 get 매개 변수 'message_read = 1'을 사용하여 페이지를 다시로드합니다. 이 GET 매개 변수를 catch하고 싶습니다. 모든 app.route (많은 정보)에 수표를 쓰는 것이 더 좋은 방법이라고 확신합니다. 제발 저에게 힌트를주세요.

감사합니다.

+0

답변을 확인하고 수락 또는 댓글을 달기 –

답변

0

당신은 decrators를 사용할 수 있습니다. 여기

here 아래 flask.The 코드와 사용자 정의 장식의 데모입니다 파이썬 장식 읽기에 대한 당신의 사용 사례에 대한 장식 정의와 사용법을 보여줍니다

코드

from flask import Flask,request 
from functools import wraps 


def popup_message(f): 
    @wraps(f) 
    def f_(*args,**argv): 
     message_read = request.args.get('message_read', None) 
     if message_read is not None: 
      return message_read 
     else: 
      return f(*args,**argv) 
    return f_ 




app = Flask(__name__) 

@app.route('/earth') 
@popup_message 
def hello_earth(): 
    return 'Hello,earth' 

@app.route('/world') 
@popup_message 
def hello_world(): 
    return 'Hello, World!' 

app.run() 

사용

앱 실행

python main.py 
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) 

/지구 및/세계에 대한 요청 (예 : message_read)

관련 문제