I am working on an assignment for a Flask application with a function that does different things based on the value of a hidden field in a form on the index.html page. I am to have only two routes: '/' (index.html) and '/process' (which performs actions on index.html).
When I run this in Flask (python server.py in a virtualenv), and click the button "Make Money" on index.html, I get this error:
"TypeError TypeError: 'ImmutableMultiDict' object is not callable"
Can someone please tell me how I can get the desired value from the hidden input?
contents of server.py
import datetime
import random
from flask import Flask, render_template, redirect, request, session
app = Flask(__name__)
app.secret_key = 'fooBarBaz'
@app.route('/')
def index():
return render_template('index.html')
@app.route('/process', methods=['GET','POST'])
def process():
if request.method == 'POST':
target = request.form('name')
if target == 'clothing':
new_money = random.randrange(10, 21)
session['balance'] += new_money
timestamp = datetime.datetime.now()
session['register'] += ("Received" + new_money + " dollars at " + timestamp.strftime("%Y/%m/%d %I:%M %p"))
return render_template('index.html')
app.run(debug=True)
contents of index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div container>
<div class='balance'>
<p>Your balance: {{ session['balance'] }}</p>
</div>
<div class="shops">
<div class="clothing">
<h2>Clothing Store</h2>
<p>(earns 10 - 20 dollars)</p>
<form action="/process" method="post">
<input type="hidden" name="clothing">
<input type="submit" value="Make Money!">
</form>
</div>
</div>
<div class="register">
<h4>Receipt Tape</h4>
<p>{{ session['register'] }}</p>
</div>
</div>
</body>
</html>