Skip to content
Sign upLog in
← Back to Community

[PYTHON] How do I change the replit database with an HTML button?

Profile icon
MrVoo

I'm making a flask thing and I'm trying to increase a value in the replit database by 1. Anyone know how to change the database by pressing a button on the page?

Answered by CosmicBear [earned 5 cycles]
View Answer
Voters
Profile icon
sobakarooted
Profile icon
rickysong
Profile icon
MrVoo
Comments
hotnewtop
Profile icon
CosmicBear
<html> {{ test }} <a href="/add"><button>Add 1</button></a> </html>
@app.route('/add') def add(): db['num'] += 1 return redirect('/')

or,

<html> <form method="POST"> <button type="submit">Add 1</button> </form> </html>
@app.route('/') def index(): val = db["num"] if request.method == "POST": val += 1 return render_template("index.html", test = val)
Profile icon
VulcanWM

Make a app route in which you do the increase function and make the button redirect to that route

Profile icon
MrVoo

@VulcanWM
What would that look like? I'm pretty bad at flask

Profile icon
VulcanWM

Do the /change route in this repl: https://replit.com/@VulcanWM/casino#app.py for the Python part
For the html, make a link for the route /change and style it as a button

@MrVoo