林獲得項目從顯示HTML表單的Python瓶從HTML選擇表單
無法得到任何東西,我總是得到"ValueError: View function did not return a response"
有人可以幫助我在這裏嗎?我已經嘗試了可以在網上找到的request.get的每個變體。此外,如果我指定我的表單應該使用後,它使用無論如何 - 任何人都知道這是爲什麼?
進出口新的燒瓶中,所以請原諒我的無知!
在此先感謝。
蟒蛇文件(routes.py)
from flask import Flask, render_template, request
import os
app = Flask(__name__)
musicpath = os.listdir(r"C:\Users\Oscar\Music\iTunes\iTunes Media\Music")
lsize = str(len(musicpath))
looper = len(musicpath)
@app.route('/')
def home():
return render_template('home.html', lsize=20, looper=looper, musicpath=musicpath)
@app.route('/pop', methods=['POST', 'GET'])
def pop():
if request.method == "GET":
text = request.args.get('som')
return text
#Have tried every variation of request.get
@app.route('/about')
def about():
name = "Hello!"
return render_template('about.html', name=name)
if __name__ == '__main__':
app.run(debug=True)
HTML文件(home.html做爲)
{% extends "layout.html" %}
{% block content %}
<div class="jumbo">
<h2>A Music app!<h2>
</div>
<div>
{% if lsize %}
<form action="/pop">
<select id="som" size="20">
{% for i in range(looper):%}
<option value="{{i}}">{{ musicpath[i] }}</option>
{% endfor %}
</select>
</form>
{% endif %}
</div>
<a href="{{ url_for('pop') }}">Select,</a>
{% endblock %}
對不起,我最初嘗試了它的名字,只是再次 - 沒有改變錯誤相同 – user3788339