[英]How can I reset a session without a separate @app.route in flask?
[英]How to separate flask app.route order of events
我有一個小程序,當在 html 頁面上單擊一個按鈕時,它會打開一封 Outlook 電子郵件。 問題是,我不知道我的 app.route 對象的順序和我的 html 頁面中發布的數據。
我的html(openemailJS.html):
我的燒瓶應用程序:
import win32com.client
from flask import Flask, render_template, jsonify, json, url_for, request, redirect
import pythoncom, time, os, sys
app = Flask(__name__)
@app.route('/',methods = ['POST', 'GET'])
def index():
if request.method == 'POST':
emailid = request.args.get('nm')
time.sleep(1)
pythoncom.CoInitialize()
outlook = win32com.client.dynamic.Dispatch("Outlook.Application").GetNameSpace('MAPI')
inbox = outlook.GetDefaultFolder(6)
sentbox = outlook.GetDefaultFolder(5)
all_sentbox = sentbox.Items
all_inbox = inbox.Items
tryopen = outlook.GetItemFromID(emailid)
tryopen.display()
return render_template('openemailJS.html')
print(emailid)
else:
time.sleep(1)
emailid = request.args.get('nm')
#emailid = request.form.get('nm')
time.sleep(1)
pythoncom.CoInitialize()
outlook = win32com.client.dynamic.Dispatch("Outlook.Application").GetNameSpace('MAPI')
inbox = outlook.GetDefaultFolder(6)
sentbox = outlook.GetDefaultFolder(5)
all_sentbox = sentbox.Items
all_inbox = inbox.Items
tryopen = outlook.GetItemFromID(emailid)
tryopen.display()
print(user)
return render_template('openemailJS.html')
我想我需要將' return render_template('openemailJS.html') '分成它自己的 app.route('/something here/') 但我不知道該怎么做。
目前,當我按原樣運行時,emailid 不會在 def index(): 運行之前發布,從而導致“找不到參數”應該在哪里。 如果我注釋掉除“return render_template”之外的所有內容,運行程序,然后取消注釋並單擊按鈕,然后它會按應有的方式發布。
我添加了一個 if 語句來僅在表單發布時檢索數據。 我仍然認為在做任何事情之前先渲染模板是有意義的,但我不知道。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.