I did all that was stated on tutorial point (just copied and pasted), but when I tried to add a student entry,i.e. ‘Add Student’ it gives
Bad Request The browser (or proxy) sent a request that this server could not understand.
Please advise if there is anything wrong with the tutorial.
It failed at this line within def new(), in app.py:
student = students(request.form['name'], request.form['city'], request.form['addr'], request.form['pin'])
Whoever is flagging this down. Note that it is the tutorial that is filled with typos and wrong indentations. I am only a student. Shut this down and I will learn nothing.
Ref: http://www.tutorialspoint.com/flask/flask_sqlalchemy.htm
from flask import Flask, request, flash, url_for, redirect, render_template
from flask_sqlalchemy import SQLAlchemyapp = 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 = nameself.city = cityself.addr = addrself.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)