[英]How to print the value from the drop down box in flask?
This my base HTML file:这是我的基本 HTML 文件:
<html>
<head>
<title>names</title>
</head>
<body>
<div>PS: <a href="/ps">Home</a></div>
<hr>
{% block content %}{% endblock %}
</body>
</html>
This my tasks.html file这是我的 tasks.html 文件
{% extends "base.html" %}
{% block content %}
<div class="page">
<table>
<tr>
<form action="{{ url_for('new_task') }}" method="POST" class=new-task>
</tr>
<tr>
<td>
<label>name :</label>
<select name="name" width="100px">
<option value="1">name1</option>
<option value="2">name2</option>
<option value="3">name3</option>
<option value="4">name4</option>
<option value="5">name5</option>
</select>
</td>
<td>
<input class="button1" type="submit" value="Press">
</td>
</form>
</tr>
</table>
</div>
</table>
{% endblock %}
This my python file views.py这是我的 python 文件 views.py
from flask import render_template
from app import app
@app.route('/tasks', methods=['POST'])
def new_task():
tts = request.form['name']
flash(str(tts)+'is being selected')
render_template("tasks.html")
@app.route('/ps')
def ps():
render_template("ps.html")
I want to just print the value whatever is being selected from the drop down menu.我只想打印从下拉菜单中选择的任何值。 But i am getting this error "Method Not Allowed The method is not allowed for the requested URL."
但我收到此错误“方法不允许 请求的 URL 不允许该方法。” Actually i am new to flask programming Please tell me where i am doing wrong .
实际上我是烧瓶编程的新手请告诉我我做错了什么。 Help will be highly appreciated :)
帮助将不胜感激:)
Usually method not allowed has to do with form methods of GET/POST etc. I would suggest a few changes.通常不允许的方法与 GET/POST 等表单方法有关。我建议进行一些更改。
template :模板:
<form action="{{ url_for('new_task') }}" method="POST" class=new-task>
View :查看:
@app.route('/tasks/', methods=['GET','POST'])
def new_task():
if request.method == 'POST':
tts = request.form['name']
flash(str(tts)+'is being selected')
return render_template("tasks.html")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.