-2
我對燒瓶很新。試圖構建一個燒錄應用程序,從後端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/<Galactic_ID>')
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 -
爲什麼要將'returnObject'轉換成JSON字符串而不是僅僅返回它的目錄? – dirn
@davidism現在已修復。 –
@davidism關於如何將returnsObject從models.py傳遞給views.py? –