我对烧瓶很新。试图构建一个烧录应用程序,从后端neo4j获取数据并将其以JSON格式发布。最终的目标是使用d3.js进行可视化。但对于初学者,我想把它发布为JSON。用于POST请求的烧瓶404
下面是我的views.py:
import models
from models import Customer
from flask import Flask, request, session, redirect, url_for, render_template, flash,json,jsonify
import os
app = Flask(__name__)
@app.route('/',methods = ['GET','POST'])
def enter_ID():
if request.method == 'POST':
Galactic_ID = request.form['Galactic_ID']
if Customer(Galactic_ID).find():
return redirect(url_for('Customer_relationships',Galactic_ID=request.form.get('Galactic_ID')))
else:
return "Wrong Galactic_ID"
else:
return render_template('Gal.html')
@app.route('/Customer_relationships/')
def Customer_relationships(Galactic_ID):
data = Customer(Galactic_ID).get_relationships():
return render_template('rel.html',Galactic_ID=Galactic_ID,data =json.dumps(data))
if __name__ == '__main__':
host = os.getenv('IP','0.0.0.0')
port = int(os.getenv('PORT',5000))
app.secret_key = os.urandom(24)
app.run(host=host,port=port)
在views.py,客户(Galactic_ID).find()和客户(Galactic_ID).get_relationships()调用的函数找到(个体经营)和get_relationships(个体经营)下Customer类在models.py:下面
当我尝试和运行这个是HTTP调用:
127.0.0.1 - - [29/Jul/2016 17:54:53] "GET/HTTP/1.1" 200 -
127.0.0.1 - - [29/Jul/2016 17:54:56] "POST/HTTP/1.1" 302 -
127.0.0.1 - - [29/Jul/2016 17:54:56] "GET /Customer_relationships/2000000000084001287 HTTP/1.1" 200 -
127.0.0.1 - - [29/Jul/2016 17:54:56] "POST /Customer_relationships HTTP/1.1" 404 -
+0
为什么要将'returnObject'转换成JSON字符串而不是仅仅返回它的目录? –
+0
@davidism现在已修复。 –
+0
@davidism关于如何将returnsObject从models.py传递给views.py? –