在按下提交时,表单应该将值传递给服务器。但是我收到了这个 500 内部服务器错误。这是我的views.py代码:-
from app import app
from flask import render_template,request
import feedparser
import json
@app.route('/')
@app.route('/index')
def search():
return render_template('index.html')
@app.route('/searchRSS',methods=['POST'])
def search_results():
feed = feedparser.parse("http://news.google.com/news?hl=en&gl=in&q="+request.form['query']+"&um=1&output=rss" )
posts = []
for i in range(0,len(feed['entries'])):
posts.append({
'date': feed['entries'][i].title,
'title': feed['entries'][i].updated,
'description': feed['entries'][i].description
})
return json.dumps(posts, separators=(',', ':'))
这是 index.html :-
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
window.onload=function (){
$("#searcher").submit(function(ev) {
/* stop form from submitting normally */
ev.preventDefault();
$.post("/searchRSS", $("#searcher").serialize(),function(o) {document.getElementById("result").innerHTML=o;});
})};
</script>
<form id="searcher" method="post" action="#">
<input type="text" id="query" name="query" required/>
<input type="submit" value="Get Feed"/>
</form>
<div id="result"></div>