Trilobot Doesn't Work Properly With Flask

I am trying to create a Flask web interface to control the Trilobot. Unfortunately, the motors are inconsistent when we put the commands into a Flask script (see below). The motors won’t stop when we use the stop command (they keep going but slowly) and the two motors go at different speeds (pulling the car to the right) when we tell it to go straight.

Without Flask, the same commands seem to work, though there’s a slight pull to the right. Here’s our script. Is there a trick to getting it to work?

from flask import Flask, render_template
from trilobot import Trilobot
from time import sleep
import datetime
tbot = Trilobot()
app = Flask(__name__)
@app.route("/")
def hello():
    now = datetime.datetime.now()
    timeString = now.strftime("%Y-%m-%d %H:%M")
    templateData = {
      'title' : 'HELLO!',
      'time': timeString
      }
    return render_template('index.html', **templateData)
@app.route("/<direction>")
def action(direction):
    now = datetime.datetime.now()
    timeString = now.strftime("%Y-%m-%d %H:%M")
    templateData = {
        'title' : 'Moving ' + direction,
        'direction' : direction,
        'time' : timeString
        }
    if direction == "forward":
        print("going forward")
        tbot.forward(1.0)
        sleep(1)
    elif direction == "right":
        print("going right")
        tbot.turn_right(0.7)
        sleep(1)
    elif direction == "left":
        print("going left")
        tbot.turn_left(0.7)
        sleep(1)
    elif direction == "stop":
        print("stopping")
        tbot.stop()
        sleep(1)
    return render_template('index.html', **templateData)
if __name__ == "__main__":
    app.run(host='0.0.0.0', port=80, debug=True)