我做了所有在教程點(剛剛複製和粘貼)上陳述的內容,但是當我嘗試添加學生入口時, '添加學生'它給出TutorialsPoint - 燒瓶 - SQLAlchemy不工作
錯誤的請求 瀏覽器(或代理)發送請求,此服務器無法理解。
請告知教程是否有任何問題。
它沒有在內部DEF新的()這一行,在app.py:
student = students(request.form['name'], request.form['city'], request.form['addr'], request.form['pin'])
誰下垂下來。請注意,它是填充拼寫錯誤和錯誤縮進的教程。我只是一個學生。關掉這個,我什麼都不會學。
編號:http://www.tutorialspoint.com/flask/flask_sqlalchemy.htm
from flask import Flask, request, flash, url_for, redirect, render_template
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///students.sqlite3'
app.config['SECRET_KEY'] = "random string"
db = SQLAlchemy(app)
class Students(db.Model):
id = db.Column('student_id', db.Integer, primary_key = True)
name = db.Column(db.String(100))
city = db.Column(db.String(50))
addr = db.Column(db.String(200))
pin = db.Column(db.String(10))
def __init__(self, name, city, addr,pin):
self.name = name
self.city = city
self.addr = addr
self.pin = pin
@app.route('/')
def show_all():
return render_template('show_all.html', Students = Students.query.all())
@app.route('/new', methods = ['GET', 'POST'])
def new():
if request.method == 'POST':
if not request.form['name'] or not request.form['city'] or not request.form['addr']:
flash('Please enter all the fields', 'error')
else:
print "1";
student = Students(request.form['name'], request.form['city'], request.form['addr'], request.form['pin'])
print "1";
db.session.add(student)
print "1";
db.session.commit()
print "1";
flash('Record was successfully added')
print "=======>>>>>>>>>";
return redirect(url_for('show_all'))
return render_template('new.html')
if __name__ == '__main__':
db.create_all()
app.run(debug = True)
請幫助我們瞭解您的問題?...郵政編碼,完整的錯誤信息..等.. –
代碼在鏈接中。 –
@UrsaMajor ..不.. ..你輸入了什麼.. !!。這不是同一件事...可能是你有一個錯字錯誤,或其他東西... –