Skip to content
Sign UpLog In
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
3

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

MrVoo
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?

1 year ago

Voters

Comments

TopNew
1
CosmicBear
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)
1 year ago
1
VulcanWM
VulcanWM

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

1 year ago
1
MrVoo
MrVoo

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

1 year ago
1
VulcanWM
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

1 year ago
Load more