Flask请求方法从post改为get?

时间:2017-08-25 10:06:01

标签: python post get request

我正在使用flask来从其他网站获取信息,这是我的代码。 这是get_music.py,一个获取http://music.163.com/api/search/get/音乐ID的函数,当我运行它时 它独立地运行没有问题。

def get_music():
baseUrl = "http://music.163.com/api/search/get/"
parameters = {
    's': "acg",
    'limit': 100,
    'type': 1
}
response = requests.post(baseUrl, data=parameters)
answer = response.json()
print(answer)
music_id = answer['result']['songs'][0]['id']
# print(music_id)
return music_id

但是当我把它放入烧瓶中时,问题发生了,这是我的views.py代码

@main.route('/', methods=['GET', 'POST'])
def index():
music_id = get_music()
music_id = str(music_id)

return render_template("index.html", music_id=music_id)

当我调试这个问题时,我发现请求方法从post变为get。     当我作为烧瓶程序运行时,错误消息说请求方法是“GET”,但我正在使用post方法。

enter image description here

但是当我独立运行get_music.py时,它运行得非常好,  并且请求方法是post,我不知道为什么,还有其他人可以帮助我吗?

0 个答案:

没有答案
相关问题