O'Reilly logo

Modern Python Cookbook by Steven F. Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Server

  1. Start with the Parsing the query string in a request recipe as a template for a Flask application. We'll be changing the view functions in that example:
        from flask import Flask, jsonify, request, abort, make_response 
        from http import HTTPStatus 
        dealer = Flask('dealer') 
  1. Import any additional modules. In this case, we'll use the uuid module to create a unique key for a shuffled deck:
        
import uuid 

We'll also use the Werkzeug BadRequest response. This allows us to provide a detailed error message. This is a little nicer than using abort(400) for an erroneous request:

        from werkzeug.exceptions import BadRequest 
  1. Define the global state. This includes the collection of decks. It also includes the random number generator. For testing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required