

In this section, you’ve seen how Flask Blueprints work and how you can create them and use them.
Blueprint registry registration#
url_defaults is a dictionary with default values for view arguments.īeing able to do some customization at registration time, instead of at creation time, is particularly useful when you’re sharing the same Flask Blueprint in different projects.subdomain is a subdomain that Blueprint routes will match.url_prefix is an optional prefix for all the Blueprint’s routes.You can customize how the Flask Blueprint extends the application by providing some parameters to register_blueprint: Now, requests to the app for the URL / will be served using. register_blueprint(), you apply all operations recorded in the Flask Blueprint example_blueprint to app.
Blueprint registry code#
The following code block shows how this decorator is used:įrom flask import Flask from example_blueprint import example_blueprint app = Flask ( _name_ ) app. It allows you to associate a view function to a URL route. One of the most used decorators is route. The Blueprint object example_blueprint has methods and decorators that allow you to record operations to be executed when registering the Flask Blueprint in an application to extend it. Note that all paths, except root_path, are relative to the Blueprint’s directory. Root_path: the Blueprint’s root directory path, whose default value is obtained from the Blueprint’s import name Url_defaults: a dictionary of default values that this Blueprint’s views will receive

Subdomain: the subdomain that this Blueprint’s routes will match on by default Url_prefix: the path to prepend to all of the Blueprint’s URLs Template_folder: the folder containing the Blueprint’s templates Static_url_path: the URL to serve static files from Static_folder: the folder where the Blueprint’s static files can be found There are other optional arguments that you can provide to alter the Blueprint’s behavior: The second argument, _name_, is the Blueprint’s import name, which Flask uses to locate the Blueprint’s resources. The first argument, "example_blueprint", is the Blueprint’s name, which is used by Flask’s routing mechanism. Note that in the above code, some arguments are specified when creating the Blueprint object. The following code shows the Blueprint object creation:įrom flask import Blueprint example_blueprint = Blueprint ( 'example_blueprint', _name_ ) Let’s revisit the Flask Blueprint definition that you’ve seen previously and review it in detail. For example, when you associate a view to a route in a Flask Blueprint, it records this association to be made later in the application when the Blueprint is registered. They record operations to be executed later when you register them on an application. This is the key concept behind any Flask Blueprint. When you register a Flask Blueprint in an application, you’re actually extending the application with the contents of the Blueprint. It needs to be registered in an application before you can run it. However, a Flask Blueprint is not actually an application. They both can have resources, such as static files, templates, and views that are associated with routes. Each Flask Blueprint is an object that works very similarly to a Flask application. In this section, you’ll learn in detail how a Flask Blueprint is implemented and used. You’ll see a page showing the message, This is an example app. Garnish drink with twist and serve immediately.While the application is running, go to using your web browser. Strain into a chilled Champagne flute and top with sparkling wine.Ĭurl lemon peel around finger to create twist at least 6 inches long. Add ice and shake vigorously for 20 seconds. In cocktail shaker, combine gin, lemon juice, and simple syrup. Reserve lemon for another use and set peel aside.

Garnish with the cherry and orange slice.ġ 1/2 tablespoons (3/4 ounce) fresh lemon juiceġ/4 cup (2 ounces) dry sparkling wine, such as brut Champagne, chilledĭirections: Using zester or paring knife, slice peel from lemon in long, thin spiral. Cheers!ġ 1/2 oz bourbon (or rye, or Irish whiskey)ĭirections: Serve over a large ice cube (get trays here) in an old fashioned glass and serve with a festive swizzle sticks. With his-and-hers signature cocktails and a crowd pleasing punch, guests can serve themselves so you can mix and mingle. That's why we're loving this inspiring cocktail gathering designed by Blueprint Registry.
