Hello I am building a blackjack game and I am stuck the deal button is not working and I am trying to get that to redirecting to another URL. Also do I need that many variables to update the game as the client is playing ? This is my third day doing flask after and my first web application. Any help or pointing me in the right direction would be appreciated here is the HTML code for the inputs as well as my starting code on flask
<form action="/deal" method="Post" >
<input class="hit_button" type="submit" value="Hit" name="Hit"/>
<input class="stay_button" type="submit" value="Stay" name="Stay"/>
</form>
<form action="/" method="Post" >
<input class="deal_button" type="submit" value="Deal" name="Deal"/>
</form>
from flask import Flask, render_template, request, Response, redirect, url_for
import random
import main
import datetime as dt
app = Flask(__name__)
year = dt.datetime.now().year
count = 0
@app.route('/', methods=['POST', "GET"])
def home():
global count
if count == 0:
count += 1
return render_template("index.html", year=year)
elif request.method == "GET":
if request.form.get("Stay", False):
return redirect(url_for('/deal'))
@app.route('/deal', methods=['POST', "GET"])
def deal():
if len(main.player_hand) == 0:
main.start()
main.get_current_score(main.player_hand)
return render_template("index.html", year=year, player=main.player_hand, dealer=main.dealer_hand[1:],
score_d=main.get_dealer_starting_value(main.dealer_hand),
score_p=main.get_current_score(main.player_hand))
if request.method == "POST":
if request.form.get("Hit", False):
if main.get_current_score(main.player_hand) <= 21:
main.player_hand_dealt()
return render_template("index.html", year=year, player=main.player_hand, dealer=main.dealer_hand[1:],
score_d=main.get_dealer_starting_value(main.dealer_hand),
score_p=main.get_current_score(main.player_hand))