I am new to making Flask apps, so I might be missing something obvious. What I am trying to do is take a value from a slider and increment a value in my postgresql table by the slider value and then increment another value in my postgresql table by 1. I am getting the error:
werkzeug.routing.BuildError: Could not build url for endpoint 'post_to_db'. Did you mean 'static' instead?
Here is my html:
<form method="POST" action="{{ url_for('post_to_db') }}">
<input class='slider'id="mydata" name="mydata" type="range" min="0" max="10" value="5" step='1'>
<div id='button-dock'>
<button type='submit'>"Show Me Another"</button>
</div>
</form>
Here is my python:
class Dataentry(db.Model):
__tablename__ = "shoe-ratings"
id = db.Column(db.Integer, primary_key=True)
total_score = db.Column(db.Integer)
num_ratings = db.Column(db.Integer)
def __init__(self, total_score, num_ratings):
self.total_score = total_score
self.num_ratings = num_ratings
def __repr__(self):
return '<id {}>'.format(self.id)
def serialize(self):
return {
'id': self.id,
'total_score': self.total_score,
'num_ratings': self.num_ratings
}
@app.route("/virgil_io/submit/", methods=["POST"])
def post_to_db():
score = request.form['mydata']
shoe = Dataentry.query.first()
shoe.total_score = shoe.c.total_score + score
shoe.num_ratings = shoe.c.num_ratings + 1
try:
db.session.add(shoe)
db.session.commit()
except Exception as e:
print("\n FAILED entry\n")
print(e)
sys.stdout.flush()
return "Success"
@APP.route('/virgil_io/')
def index():
return flask.render_template('index.html')
Here is my directory:
Things I've tried:
methods=["POST"]
Any ideas? Thanks!
As always, it was a stupid little thing. My app was named APP
, but I was using app
for this method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.