首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在URL中更改Args时页面上的自动更新数据

在URL中更改Args时页面上的自动更新数据
EN

Stack Overflow用户
提问于 2022-06-12 11:21:48
回答 1查看 77关注 0票数 0

我有一个烧瓶应用程序,它以参数的形式从url中提取3个值,例如- ticker、start date、end date。

我面临的问题是,当我第一次点击url时,它会正确地返回数据,尽管下次我在更改参数的值时,它不能工作。

URL- 127.0.0.1:5000/api?ticker=IEX&start=25-04-2022&end=25-05-2022标准格式

尽管当我假设将开始值从25-042022更改为25-03-2022参数时,代码返回的值与第一个参数的值相同。

这是我的密码

代码语言:javascript
复制
import requests
from datetime import date 
import time
import json
import pandas as pd
import os
from flask import Flask
from flask_caching import Cache
from flask import request

config = {
    "CACHE_TYPE": "SimpleCache",  # Flask-Caching related configs
    "CACHE_DEFAULT_TIMEOUT": 0,
}

app = Flask(__name__)
# tell Flask to use the above defined config
app.config.from_mapping(config)
cache = Cache(app)

@app.route("/api")
@cache.cached(timeout=0)
def index():
    # https://www.nseindia.com/api/historical/cm/equity?symbol=IEX&series=[%22EQ%22]&from=25-04-2022&to=25-05-2022
    ticker = request.args.get( 'ticker', None)
    start = request.args.get( 'start', None) #25-04-2022
    end = request.args.get( 'end', None) #25-05-2022
    s = requests.Session()
    headers =   {'Host':'www.nseindia.com', 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0','Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Language':'en-US,en;q=0.5', 'Accept-Encoding':'gzip, deflate, br','DNT':'1', 'Connection':'keep-alive', 'Upgrade-Insecure-Requests':'1','Pragma':'no-cache','Cache-Control':'no-cache',  }
    url = 'https://www.nseindia.com/'
    step = s.get(url,headers=headers)
    api_url = f"https://www.nseindia.com/api/historical/cm/equity?symbol={ticker}&series=[%22EQ%22]&from={start}&to={end}"
    result = s.get(api_url,headers=headers).json()
    return result

if __name__ == "__main__":
    app.run(debug=True, port=int(os.environ.get('PORT', 5000)))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-12 11:52:43

这可能是因为缓存的超时值为0,因此缓存设置为无限时间

代码语言:javascript
复制
@cache.cached(timeout=0)

尝试注释掉或删除以下行

代码语言:javascript
复制
cache = Cache(app)
@cache.cached(timeout=0)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72591725

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档