我是flask-py2neo-pyhon-neo4j中的新成員,因此我需要一些幫助 我遇到以下問題。我運行/執行的主要.py是views.py我有另一個py腳本,我已經提交了一些form_data.html>更清晰 views.py --calls - > app.py - calls-- > form_action.html & form_submit.html 我怎樣才能達到這個順序? 燒瓶-Python代碼:views.pyflask-python腳本如何調用另一個flask-python腳本
@app.route('/vital', methods=['GET','POST'])
def vital():
# username = session.get('username')
name=request.form['pname']
sfx=request.form['psfx']
midname=request.form['pmidname']
bsurname=request.form['pbsurname']
# if not name:
# flash('You must give your post a name.')
# elif not sfx:
# flash('You must give your post a suffix.')
# elif not midname:
# flash('You must give your post a midname.')
# elif not bsurname:
# flash('You must give your post a bsurname.')
# else:
# User(session['username']).vital(name, sfx, midname, bsurname)
return render_template('form_action.html', username=username, sfx=sfx, midname=midname, bsurname=bsurname)
app.py
from flask import Flask, render_template, request, url_for
app = Flask(__name__)
@app.route('/')
def form():
return render_template('form_submit.html')
@app.route('/hello/', methods=['POST'])
def hello():
name=request.form['pname']
sfx=request.form['psfx']
midname=request.form['pmidname']
bsurname=request.form['pbsurname']
return render_template('form_action.html', name=name, sfx=sfx, midname=midname, bsurname=bsurname)
if __name__ == '__main__':
app.run()
send_data()
form_action.html
<html>
<head>
<title>Person</title>
<link rel=stylesheet type=text/css href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
<div id="container">
<div class="title">
<h1>Person's Vital Information</h1>
</div>
<div id="content">
Tell us about <strong>{{name}}</strong> {{bsurname}}!
</div>
<div class="title">
<h1>Flask code</h1>
</div>
<code><pre>
@app.route('/hello/', methods=['POST'])
def hello():
name=request.form['pname']
sfx=request.form['psfx']
midname=request.form['pmidname']
bsurname=request.form['pbsurname']
return render_template('form_action.html', name=name, sfx=sfx, midname=midname, bsurname=bsurname)
</pre></code>
</div>
</div>
</body>
</html>
form_submit.html
<html>
<head>
<title>Person</title>
<link rel=stylesheet type=text/css href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
<div id="container">
<div class="title">
<h1>Person's Vital Information</h1>
</div>
<div id="content">
<form method="post" action="{{ url_for('hello') }}">
<label for="pname">Name:</label>
<input type="text" name="pname" /><br />
<label for="psfx">Suffix: </label>
<input type="text" name="psfx" /><br />
<label for="pmidname">Middle Name: </label>
<input type="text" name="pmidname" /><br />
<label for="pbsurname">Birth Surname: </label>
<input type="text" name="pbsurname" /><br />
<input type="submit" />
</form>
</div>
<div class="title">
<h1>Flask code</h1>
</div>
<code><pre>
@app.route('/')
def form():
return render_template('form_submit.html')
</pre></code>
</div>
</div>
</body>
</html>
你好阿德里亞諾,我做了完全一樣的你說的,但當我按下鏈接「你好」時,我得到的錯誤「方法不允許 該方法不允許請求的URL。 – Antwnina
將'@ app.route('/ hello /',methods = ['POST'])'改爲'@ app.route('/ hello /',methods = ['POST','GET'])' –