【问题标题】:SQL -- temporarily snapshotting/archiving a query across Flask pagesSQL——临时快照/归档跨 Flask 页面的查询
【发布时间】:2018-11-21 21:56:31
【问题描述】:

我想暂时保存跨多个烧瓶路线的一个查询的信息。

基本上,我有一个专门用于查询的功能。我使用查询来获取随机 ID。使用此 ID,我收集此实例所需的所有其他信息。然后在 route1 中使用它(我在这里通过字典调用它)。用户输入一些内容,然后使用“url_for”将所有信息传输到 route2。

程序搞砸了,因为 route2 没有对两条路由使用相同的 id,而是再次查询并使用基于不同 id 的不同信息集。我希望两条路线的 id 保持不变。我希望它在每次刷新或访问 route1 时更改,但保持不变。

让我知道任何想法或想法!

def get_db():
    random_id = db.execute("SELECT id FROM list ORDER BY RANDOM() LIMIT 1").fetchone()[0]

    score = query to select score using {random_id}
    image = quesry to select score using {random_id}
    info = {
    'random_id': random_id,
    'image': image,
    'score': score
    }
    return info

@app.route('route1')
data=det_db():
def functionA():
uses data.get() to call information from query in dictionary 
return redirect(url_for('fucntionB', random_id=random_id, image=image, score=score))

@app.route('route2')
def functionB():
info=request.args
random_id=info.get('random_id')
image=info.get('image')
score=info.get('score')

【问题讨论】:

    标签: python sql flask


    【解决方案1】:

    您是否研究过本地存储?也许你可以在 route1 命中时将 id 存储在本地存储中,然后在 route2 命中时访问它。

    <script>
    localstorage.setItem('name', 'value')
    </script>
    
    <script>
    var item = localStorage.getItem('name');
    </script>
    

    这两个脚本将允许您在本地存储中存储和检索。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-03
      • 1970-01-01
      • 2021-06-17
      • 1970-01-01
      • 2022-08-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多