docstring_tokens
stringlengths
0
76.5k
code_tokens
stringlengths
75
1.81M
label_window
listlengths
4
2.12k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
self, f: T_template_context_processor ) -> T_template_context_processor:
<mask> return f <mask> <mask> @setupmethod <mask> def app_context_processor( <mask> self, f: ft.TemplateContextProcessorCallable <mask> ) -> ft.TemplateContextProcessorCallable: <mask> """Like :meth:`Flask.context_processor` but for a blueprint. Such a <mask> functi...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/blueprints.py
) -> t.Callable[[T_error_handler], T_error_handler]:
<mask> <mask> @setupmethod <mask> def app_errorhandler( <mask> self, code: t.Union[t.Type[Exception], int] <mask> ) -> t.Callable[[ft.ErrorHandlerDecorator], ft.ErrorHandlerDecorator]: <mask> """Like :meth:`Flask.errorhandler` but for a blueprint. This <mask> handler is used...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/blueprints.py
def decorator(f: T_error_handler) -> T_error_handler:
<mask> """Like :meth:`Flask.errorhandler` but for a blueprint. This <mask> handler is used for all requests, even if outside of the blueprint. <mask> """ <mask> <mask> def decorator(f: ft.ErrorHandlerDecorator) -> ft.ErrorHandlerDecorator: <mask> self.record_once(lamb...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/blueprints.py
self, f: T_url_value_preprocessor ) -> T_url_value_preprocessor:
<mask> return decorator <mask> <mask> @setupmethod <mask> def app_url_value_preprocessor( <mask> self, f: ft.URLValuePreprocessorCallable <mask> ) -> ft.URLValuePreprocessorCallable: <mask> """Same as :meth:`url_value_preprocessor` but application wide.""" <mask> sel...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/blueprints.py
def app_url_defaults(self, f: T_url_defaults) -> T_url_defaults:
<mask> ) <mask> return f <mask> <mask> @setupmethod <mask> def app_url_defaults(self, f: ft.URLDefaultCallable) -> ft.URLDefaultCallable: <mask> """Same as :meth:`url_defaults` but application wide.""" <mask> self.record_once( <mask> lambda s: s.app.url_defau...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/blueprints.py
T_after_request = t.TypeVar("T_after_request", bound=ft.AfterRequestCallable) T_before_request = t.TypeVar("T_before_request", bound=ft.BeforeRequestCallable) T_error_handler = t.TypeVar("T_error_handler", bound=ft.ErrorHandlerCallable) T_teardown = t.TypeVar("T_teardown", bound=ft.TeardownCallable) T_template_context_...
<mask> _sentinel = object() <mask> <mask> F = t.TypeVar("F", bound=t.Callable[..., t.Any]) <mask> <mask> <mask> def setupmethod(f: F) -> F: <mask> f_name = f.__name__ <mask> </s> Improve decorator typing (#4676) * Add a missing setupmethod decorator * Improve the decorator typing This will allow...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
) -> t.Callable[[T_route], T_route]:
<mask> self, <mask> method: str, <mask> rule: str, <mask> options: dict, <mask> ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]: <mask> if "methods" in options: <mask> raise TypeError("Use the 'route' decorator to use the 'methods' argument.") <mas...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
def get(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:
<mask> <mask> return self.route(rule, methods=[method], **options) <mask> <mask> @setupmethod <mask> def get( <mask> self, rule: str, **options: t.Any <mask> ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]: <mask> """Shortcut for :meth:`route` with ``methods=["GET"]...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
def post(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:
<mask> """ <mask> return self._method_route("GET", rule, options) <mask> <mask> @setupmethod <mask> def post( <mask> self, rule: str, **options: t.Any <mask> ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]: <mask> """Shortcut for :meth:`route` with ``methods=...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
def put(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:
<mask> """ <mask> return self._method_route("POST", rule, options) <mask> <mask> @setupmethod <mask> def put( <mask> self, rule: str, **options: t.Any <mask> ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]: <mask> """Shortcut for :meth:`route` with ``methods=...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
def delete(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:
<mask> """ <mask> return self._method_route("PUT", rule, options) <mask> <mask> @setupmethod <mask> def delete( <mask> self, rule: str, **options: t.Any <mask> ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]: <mask> """Shortcut for :meth:`route` with ``method...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
def patch(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:
<mask> """ <mask> return self._method_route("DELETE", rule, options) <mask> <mask> @setupmethod <mask> def patch( <mask> self, rule: str, **options: t.Any <mask> ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]: <mask> """Shortcut for :meth:`route` with ``meth...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
def route(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:
<mask> """ <mask> return self._method_route("PATCH", rule, options) <mask> <mask> @setupmethod <mask> def route( <mask> self, rule: str, **options: t.Any <mask> ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]: <mask> """Decorate a view function to register it...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
def decorator(f: T_route) -> T_route:
<mask> :param options: Extra options passed to the <mask> :class:`~werkzeug.routing.Rule` object. <mask> """ <mask> <mask> def decorator(f: ft.RouteDecorator) -> ft.RouteDecorator: <mask> endpoint = options.pop("endpoint", None) <mask> self.add_url_rul...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
view_func: t.Optional[ft.RouteCallable] = None,
<mask> def add_url_rule( <mask> self, <mask> rule: str, <mask> endpoint: t.Optional[str] = None, <mask> view_func: t.Optional[ft.ViewCallable] = None, <mask> provide_automatic_options: t.Optional[bool] = None, <mask> **options: t.Any, <mask> ) -> None: <m...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
def endpoint(self, endpoint: str) -> t.Callable[[F], F]:
<mask> """ <mask> raise NotImplementedError <mask> <mask> @setupmethod <mask> def endpoint(self, endpoint: str) -> t.Callable: <mask> """Decorate a view function to register it for the given <mask> endpoint. Used if a rule is added without a ``view_func`` with <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
def decorator(f: F) -> F:
<mask> :param endpoint: The endpoint name to associate with the view <mask> function. <mask> """ <mask> <mask> def decorator(f): <mask> self.view_functions[endpoint] = f <mask> return f <mask> <mask> return decorator <mask> </s> Improve d...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
def before_request(self, f: T_before_request) -> T_before_request:
<mask> <mask> return decorator <mask> <mask> @setupmethod <mask> def before_request(self, f: ft.BeforeRequestCallable) -> ft.BeforeRequestCallable: <mask> """Register a function to run before each request. <mask> <mask> For example, this can be used to open a database connecti...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
def after_request(self, f: T_after_request) -> T_after_request:
<mask> self.before_request_funcs.setdefault(None, []).append(f) <mask> return f <mask> <mask> @setupmethod <mask> def after_request(self, f: ft.AfterRequestCallable) -> ft.AfterRequestCallable: <mask> """Register a function to run after each request to this object. <mask> <mask...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
def teardown_request(self, f: T_teardown) -> T_teardown:
<mask> self.after_request_funcs.setdefault(None, []).append(f) <mask> return f <mask> <mask> @setupmethod <mask> def teardown_request(self, f: ft.TeardownCallable) -> ft.TeardownCallable: <mask> """Register a function to be run at the end of each request, <mask> regardles...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
self, f: T_template_context_processor, ) -> T_template_context_processor:
<mask> return f <mask> <mask> @setupmethod <mask> def context_processor( <mask> self, f: ft.TemplateContextProcessorCallable <mask> ) -> ft.TemplateContextProcessorCallable: <mask> """Registers a template context processor function.""" <mask> self.template_context_pr...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
self, f: T_url_value_preprocessor, ) -> T_url_value_preprocessor:
<mask> return f <mask> <mask> @setupmethod <mask> def url_value_preprocessor( <mask> self, f: ft.URLValuePreprocessorCallable <mask> ) -> ft.URLValuePreprocessorCallable: <mask> """Register a URL value preprocessor function for all view <mask> functions in the applic...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
def url_defaults(self, f: T_url_defaults) -> T_url_defaults:
<mask> self.url_value_preprocessors[None].append(f) <mask> return f <mask> <mask> @setupmethod <mask> def url_defaults(self, f: ft.URLDefaultCallable) -> ft.URLDefaultCallable: <mask> """Callback function for URL defaults for all view functions of the <mask> application. ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
) -> t.Callable[[T_error_handler], T_error_handler]:
<mask> <mask> @setupmethod <mask> def errorhandler( <mask> self, code_or_exception: t.Union[t.Type[Exception], int] <mask> ) -> t.Callable[[ft.ErrorHandlerDecorator], ft.ErrorHandlerDecorator]: <mask> """Register a function to handle errors by code or exception class. <mask> <mask>...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
def decorator(f: T_error_handler) -> T_error_handler:
<mask> :param code_or_exception: the code as integer for the handler, or <mask> an arbitrary exception <mask> """ <mask> <mask> def decorator(f: ft.ErrorHandlerDecorator) -> ft.ErrorHandlerDecorator: <mask> self.register_error_handler(code_or_...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/scaffold.py
AfterRequestCallable = t.Union[ t.Callable[[ResponseClass], ResponseClass], t.Callable[[ResponseClass], t.Awaitable[ResponseClass]], ] BeforeFirstRequestCallable = t.Union[ t.Callable[[], None], t.Callable[[], t.Awaitable[None]] ] BeforeRequestCallable = t.Union[ t.Callable[[], t.Optional[ResponseReturn...
<mask> # callback annotated with flask.Response fail type checking. <mask> ResponseClass = t.TypeVar("ResponseClass", bound="Response") <mask> <mask> AppOrBlueprintKey = t.Optional[str] # The App key is None, whereas blueprints are named <mask> AfterRequestCallable = t.Callable[[ResponseClass], ResponseClass] <...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/typing.py
<mask> # https://github.com/pallets/flask/issues/4095 <mask> # https://github.com/pallets/flask/issues/4295 <mask> # https://github.com/pallets/flask/issues/4297 <mask> ErrorHandlerCallable = t.Callable[[t.Any], ResponseReturnValue] <mask> ErrorHandlerDecorator = t.TypeVar("ErrorHandlerDecorator", bound=ErrorHandl...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/typing.py
RouteCallable = t.Union[ t.Callable[..., ResponseReturnValue], t.Callable[..., t.Awaitable[ResponseReturnValue]], ]
<mask> # https://github.com/pallets/flask/issues/4297 <mask> ErrorHandlerCallable = t.Callable[[t.Any], ResponseReturnValue] <mask> ErrorHandlerDecorator = t.TypeVar("ErrorHandlerDecorator", bound=ErrorHandlerCallable) <mask> <mask> ViewCallable = t.Callable[..., ResponseReturnValue] <mask> RouteDecorator = t.Ty...
[ "keep", "keep", "keep", "keep", "replace", "replace" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/typing.py
) -> ft.RouteCallable:
<mask> <mask> @classmethod <mask> def as_view( <mask> cls, name: str, *class_args: t.Any, **class_kwargs: t.Any <mask> ) -> ft.ViewCallable: <mask> """Convert the class into a view function that can be registered <mask> for a route. <mask> <mask> By default, the ge...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
src/flask/views.py
@app.route("/async") async def async_route() -> str: return "Hello"
<mask> return stream_template("index.html", name="Hello") <mask> <mask> <mask> class RenderTemplateView(View): <mask> def __init__(self: RenderTemplateView, template_name: str) -> None: <mask> self.template_name = template_name <mask> </s> Improve decorator typing (#4676) * Add a missing set...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9b44bf2818d8e3cde422ad7f43fb33dfc6737289
tests/typing/typing_route.py
Installing Flask installs the ``flask`` script, a `Click`_ command line interface, in your virtualenv. Executed from the terminal, this script gives access to built-in, extension, and application-defined commands. The ``--help`` option will give more information about any commands and options.
<mask> <mask> Command Line Interface <mask> ====================== <mask> <mask> .. versionadded:: 0.11 <mask> <mask> .. currentmodule:: flask <mask> <mask> One of the nice new features in Flask 0.11 is the built-in integration of <mask> the `click <http://click.pocoo.org/>`_ command line interface. This...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
.. _Click: http://click.pocoo.org/
<mask> ====================== <mask> <mask> .. versionadded:: 0.11 <mask> <mask> .. currentmodule:: flask <mask> <mask> One of the nice new features in Flask 0.11 is the built-in integration of <mask> the `click <http://click.pocoo.org/>`_ command line interface. This <mask> enables a wide range of new fea...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
<mask> .. versionadded:: 0.11 <mask> <mask> .. currentmodule:: flask <mask> <mask> One of the nice new features in Flask 0.11 is the built-in integration of <mask> the `click <http://click.pocoo.org/>`_ command line interface. This <mask> enables a wide range of new features for the Flask ecosystem and your o...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
Application Discovery ---------------------
<mask> the `click <http://click.pocoo.org/>`_ command line interface. This <mask> enables a wide range of new features for the Flask ecosystem and your own <mask> applications. <mask> <mask> Basic Usage <mask> ----------- <mask> <mask> After installation of Flask you will now find a :command:`flask` script ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
The ``flask`` command is installed by Flask, not your application; it must be told where to find your application in order to use it. The ``FLASK_APP`` environment variable is used to specify how to load the application.
<mask> <mask> Basic Usage <mask> ----------- <mask> <mask> After installation of Flask you will now find a :command:`flask` script <mask> installed into your virtualenv. If you don't want to install Flask or you <mask> have a special use-case you can also use ``python -m flask`` to accomplish <mask> exactly ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
Unix Bash (Linux, Mac, etc.)::
<mask> installed into your virtualenv. If you don't want to install Flask or you <mask> have a special use-case you can also use ``python -m flask`` to accomplish <mask> exactly the same. <mask> <mask> The way this script works is by providing access to all the commands on <mask> your Flask application's :attr:...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
$ export FLASK_APP=hello $ flask run
<mask> your Flask application's :attr:`Flask.cli` instance as well as some <mask> built-in commands that are always there. Flask extensions can also <mask> register more commands there if they desire so. <mask> <mask> For the :command:`flask` script to work, an application needs to be discovered. <mask> Flask l...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
Windows CMD::
<mask> For the :command:`flask` script to work, an application needs to be discovered. <mask> Flask looks for a module named :file:`wsgi.py` or :file:`app.py` by default, <mask> and if it finds one it assumes the application is defined in it. <mask> <mask> You can instruct Flask to look for the application in a d...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
> set FLASK_APP=hello > flask run
<mask> exporting the ``FLASK_APP`` environment variable. It can be either set to an <mask> import path or to a filename of a Python module that contains a Flask <mask> application. <mask> <mask> In that imported file the name of the app needs to be called ``app`` or <mask> optionally be specified after a colon. ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
Windows PowerShell::
<mask> optionally be specified after a colon. For instance <mask> ``mymodule:application`` would tell it to use the `application` object in <mask> the :file:`mymodule.py` file. <mask> <mask> Given a :file:`hello.py` file with the application in it named ``app`` <mask> this is how it can be run. <mask> <mask>...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
> $env:FLASK_APP = "hello" > flask run
<mask> <mask> Given a :file:`hello.py` file with the application in it named ``app`` <mask> this is how it can be run. <mask> <mask> Environment variables (On Windows use ``set`` instead of ``export``):: <mask> <mask> export FLASK_APP=hello <mask> flask run <mask> <mask> Or with a filename:: </s>...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
While ``FLASK_APP`` supports a variety of options for specifying your application, most use cases should be simple. Here are the typical values:
<mask> this is how it can be run. <mask> <mask> Environment variables (On Windows use ``set`` instead of ``export``):: <mask> <mask> export FLASK_APP=hello <mask> flask run <mask> <mask> Or with a filename:: <mask> <mask> export FLASK_APP=/path/to/hello.py <mask> flask run </s> rewrite c...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
(nothing) The file :file:`wsgi.py` is imported, automatically detecting an app (``app``). This provides an easy way to create an app from a factory with extra arguments.
<mask> <mask> export FLASK_APP=hello <mask> flask run <mask> <mask> Or with a filename:: <mask> <mask> export FLASK_APP=/path/to/hello.py <mask> flask run <mask> <mask> Virtualenv Integration </s> rewrite cli docs reflects the current FLASK_APP detection </s> remove export FLASK_APP=/...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
``FLASK_APP=hello`` The name is imported, automatically detecting an app (``app``) or factory (``create_app``).
<mask> flask run <mask> <mask> Or with a filename:: <mask> <mask> export FLASK_APP=/path/to/hello.py <mask> flask run <mask> <mask> Virtualenv Integration <mask> ---------------------- <mask> <mask> If you are constantly working with a virtualenv you can also put the </s> rewrite cli docs re...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
----
<mask> <mask> export FLASK_APP=/path/to/hello.py <mask> flask run <mask> <mask> Virtualenv Integration <mask> ---------------------- <mask> <mask> If you are constantly working with a virtualenv you can also put the <mask> ``export FLASK_APP`` into your ``activate`` script by adding it to the <mask...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
``FLASK_APP`` has three parts: an optional path that sets the current working directory, a Python file or dotted import path, and an optional variable name of the instance or factory. If the name is a factory, it can optionally be followed by arguments in parentheses. The following values demonstrate these parts:
<mask> <mask> Virtualenv Integration <mask> ---------------------- <mask> <mask> If you are constantly working with a virtualenv you can also put the <mask> ``export FLASK_APP`` into your ``activate`` script by adding it to the <mask> bottom of the file. That way every time you activate your virtualenv you <...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
``FLASK_APP=src/hello`` Sets the current working directory to ``src`` then imports ``hello``.
<mask> ``export FLASK_APP`` into your ``activate`` script by adding it to the <mask> bottom of the file. That way every time you activate your virtualenv you <mask> automatically also activate the correct application name. <mask> <mask> Edit the activate script for the shell you use. For example: <mask> <mask...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
``FLASK_APP=hello.web`` Imports the path ``hello.web``.
<mask> automatically also activate the correct application name. <mask> <mask> Edit the activate script for the shell you use. For example: <mask> <mask> Unix Bash: ``venv/bin/activate``:: <mask> <mask> FLASK_APP=hello <mask> export FLASK_APP <mask> <mask> Windows CMD.exe: ``venv\Scripts\activate....
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
``FLASK_APP=hello:app2`` Uses the ``app2`` Flask instance in ``hello``.
<mask> Edit the activate script for the shell you use. For example: <mask> <mask> Unix Bash: ``venv/bin/activate``:: <mask> <mask> FLASK_APP=hello <mask> export FLASK_APP <mask> <mask> Windows CMD.exe: ``venv\Scripts\activate.bat``:: <mask> <mask> set "FLASK_APP=hello" <mask> :END </s> r...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
``FLASK_APP="hello:create_app('dev')"`` The ``create_app`` factory in ``hello`` is called with the string ``'dev'`` as the argument.
<mask> <mask> FLASK_APP=hello <mask> export FLASK_APP <mask> <mask> Windows CMD.exe: ``venv\Scripts\activate.bat``:: <mask> <mask> set "FLASK_APP=hello" <mask> :END <mask> <mask> Debug Flag </s> rewrite cli docs reflects the current FLASK_APP detection </s> remove set "FLASK_APP=hello...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
If ``FLASK_APP`` is not set, the command will look for a file called :file:`wsgi.py` or :file:`app.py` and try to detect an application instance or factory.
<mask> export FLASK_APP <mask> <mask> Windows CMD.exe: ``venv\Scripts\activate.bat``:: <mask> <mask> set "FLASK_APP=hello" <mask> :END <mask> <mask> Debug Flag <mask> ---------- <mask> <mask> The :command:`flask` script can also be instructed to enable the debug </s> rewrite cli docs reflect...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
Within the given import, the command looks for an application instance named ``app`` or ``application``, then any application instance. If no instance is found, the command looks for a factory function named ``create_app`` or ``make_app`` that returns an instance.
<mask> <mask> set "FLASK_APP=hello" <mask> :END <mask> <mask> Debug Flag <mask> ---------- <mask> <mask> The :command:`flask` script can also be instructed to enable the debug <mask> mode of the application automatically by exporting ``FLASK_DEBUG``. If <mask> set to ``1`` debug is enabled or ``0`...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
When calling an application factory, if the factory takes an argument named ``info``, then the :class:`~cli.ScriptInfo` instance is passed as a keyword argument. If parentheses follow the factory name, their contents are parsed as Python literals and passes as arguments to the function. This means that strings must sti...
<mask> <mask> Debug Flag <mask> ---------- <mask> <mask> The :command:`flask` script can also be instructed to enable the debug <mask> mode of the application automatically by exporting ``FLASK_DEBUG``. If <mask> set to ``1`` debug is enabled or ``0`` disables it:: <mask> <mask> export FLASK_DEBUG=1 <...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
<mask> The :command:`flask` script can also be instructed to enable the debug <mask> mode of the application automatically by exporting ``FLASK_DEBUG``. If <mask> set to ``1`` debug is enabled or ``0`` disables it:: <mask> <mask> export FLASK_DEBUG=1 <mask> <mask> Running a Shell <mask> --------------- ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
Run the Development Server --------------------------
<mask> set to ``1`` debug is enabled or ``0`` disables it:: <mask> <mask> export FLASK_DEBUG=1 <mask> <mask> Running a Shell <mask> --------------- <mask> <mask> To run an interactive Python shell you can use the ``shell`` command:: <mask> <mask> flask shell <mask> </s> rewrite cli docs reflect...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
The :func:`run <cli.run_command>` command will start the development server. It replaces the :meth:`Flask.run` method in most cases. ::
<mask> <mask> Running a Shell <mask> --------------- <mask> <mask> To run an interactive Python shell you can use the ``shell`` command:: <mask> <mask> flask shell <mask> <mask> This will start up an interactive Python shell, setup the correct <mask> application context and setup the local variables i...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
$ flask run * Serving Flask app "hello" * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
<mask> --------------- <mask> <mask> To run an interactive Python shell you can use the ``shell`` command:: <mask> <mask> flask shell <mask> <mask> This will start up an interactive Python shell, setup the correct <mask> application context and setup the local variables in the shell. This is <mask> don...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
.. warning:: Do not use this command to run your application in production. Only use the development server during development. The development server is provided for convenience, but is not designed to be particularly secure, stable, or efficient. See :ref:`deployment` for how to run in production.
<mask> To run an interactive Python shell you can use the ``shell`` command:: <mask> <mask> flask shell <mask> <mask> This will start up an interactive Python shell, setup the correct <mask> application context and setup the local variables in the shell. This is <mask> done by invoking the :meth:`Flask.ma...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
<mask> application context and setup the local variables in the shell. This is <mask> done by invoking the :meth:`Flask.make_shell_context` method of the <mask> application. By default you have access to your ``app`` and :data:`g`. <mask> <mask> Custom Commands <mask> --------------- <mask> <mask> If you wa...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
Open a Shell ------------
<mask> <mask> import click <mask> from flask import Flask <mask> <mask> app = Flask(__name__) <mask> <mask> @app.cli.command() <mask> def initdb(): <mask> """Initialize the database.""" <mask> click.echo('Init the db') </s> rewrite cli docs reflects the current FLASK_AP...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
To explore the data in your application, you can start an interactive Python shell with the :func:`shell <cli.shell_command>` command. An application context will be active, and the app instance will be imported. ::
<mask> from flask import Flask <mask> <mask> app = Flask(__name__) <mask> <mask> @app.cli.command() <mask> def initdb(): <mask> """Initialize the database.""" <mask> click.echo('Init the db') <mask> <mask> The command will then show up on the command line:: <mask> <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
$ flask shell Python 3.6.2 (default, Jul 20 2017, 03:52:27) [GCC 7.1.1 20170630] on linux App: example Instance: /home/user/Projects/hello/instance >>>
<mask> def initdb(): <mask> """Initialize the database.""" <mask> click.echo('Init the db') <mask> <mask> The command will then show up on the command line:: <mask> <mask> $ flask initdb <mask> Init the db <mask> <mask> Application Context </s> rewrite cli docs reflects the cur...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
Use :meth:`~Flask.shell_context_processor` to add other automatic imports.
<mask> click.echo('Init the db') <mask> <mask> The command will then show up on the command line:: <mask> <mask> $ flask initdb <mask> Init the db <mask> <mask> Application Context <mask> ------------------- <mask> <mask> Most commands operate on the application so it makes a lot of sense...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
<mask> <mask> $ flask initdb <mask> Init the db <mask> <mask> Application Context <mask> ------------------- <mask> <mask> Most commands operate on the application so it makes a lot of sense if <mask> they have the application context setup. Because of this, if you register <mask> a callback on ``...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
Debug Mode ----------
<mask> <mask> Application Context <mask> ------------------- <mask> <mask> Most commands operate on the application so it makes a lot of sense if <mask> they have the application context setup. Because of this, if you register <mask> a callback on ``app.cli`` with the :meth:`~flask.cli.AppGroup.command` the ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
Set the :envvar:`FLASK_DEBUG` environment variable to override the application's :attr:`~Flask.debug` flag. The value ``1`` enables it, ``0`` disables it. Forcing the debug flag on also enables the debugger and reloader when running the development server. ::
<mask> which informs the cli system to ensure that an application context is set <mask> up. This behavior is not available if a command is added later with <mask> :func:`~click.Group.add_command` or through other means. <mask> <mask> It can also be disabled by passing ``with_appcontext=False`` to the <mask> dec...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
$ FLASK_DEBUG=1 flask run * Serving Flask app "hello" * Forcing debug mode on * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) * Restarting with inotify reloader * Debugger is active! * Debugger PIN: 223-456-919
<mask> <mask> It can also be disabled by passing ``with_appcontext=False`` to the <mask> decorator:: <mask> <mask> @app.cli.command(with_appcontext=False) <mask> def example(): <mask> pass <mask> <mask> <mask> .. _dotenv: <mask> <mask> Loading Environment Variables From ``.env`` Files ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
Environment Variables From dotenv --------------------------------- Rather than setting ``FLASK_APP`` each time you open a new terminal, you can use Flask's dotenv support to set environment variables automatically.
<mask> <mask> <mask> .. _dotenv: <mask> <mask> Loading Environment Variables From ``.env`` Files <mask> ------------------------------------------------- <mask> <mask> If `python-dotenv`_ is installed, running the :command:`flask` command will set <mask> environment variables defined in the files :file:`.e...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
If `python-dotenv`_ is installed, running the ``flask`` command will set
<mask> <mask> Loading Environment Variables From ``.env`` Files <mask> ------------------------------------------------- <mask> <mask> If `python-dotenv`_ is installed, running the :command:`flask` command will set <mask> environment variables defined in the files :file:`.env` and :file:`.flaskenv`. <mask> Thi...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
Directories are scanned upwards from the directory you call ``flask``
<mask> which are used over those set in :file:`.flaskenv`. :file:`.flaskenv` should be <mask> used for public variables, such as ``FLASK_APP``, while :file:`.env` should not <mask> be committed to your repository so that it can set private variables. <mask> <mask> Directories are scanned upwards from the director...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
The files are only loaded by the ``flask`` command or calling :meth:`~Flask.run`. If you would like to load these files when running in production, you should call :func:`~cli.load_dotenv` manually.
<mask> from to locate the files. The current working directory will be set to the <mask> location of the file, with the assumption that that is the top level project <mask> directory. <mask> <mask> The files are only loaded by the :command:`flask` command or calling <mask> :meth:`~flask.Flask.run`. If you would ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
Environment Variables From virtualenv ------------------------------------- If you do not want to install dotenv support, you can still set environment variables by adding them to the end of the virtualenv's :file:`activate` script. Activating the virtualenv will set the variables. Unix Bash, :file:`venv/bin/activate...
<mask> <mask> .. _python-dotenv: https://github.com/theskumar/python-dotenv#readme <mask> <mask> <mask> Factory Functions <mask> ----------------- <mask> <mask> In case you are using factory functions to create your application (see <mask> :ref:`app-factories`) you will discover that the :command:`flask` c...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
app = Flask(__name__)
<mask> <mask> Factory Functions <mask> ----------------- <mask> <mask> In case you are using factory functions to create your application (see <mask> :ref:`app-factories`) you will discover that the :command:`flask` command <mask> cannot work with them directly. Flask won't be able to figure out how to <mask...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
@app.cli.command() @click.argument('name') def create_user(name): ...
<mask> the recommendation is to create a separate file that instantiates <mask> applications. This is not the only way to make this work. Another is the <mask> :ref:`custom-scripts` support. <mask> <mask> For instance if you have a factory function that creates an application <mask> from a filename you could m...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
::
<mask> For instance if you have a factory function that creates an application <mask> from a filename you could make a separate file that creates such an <mask> application from an environment variable. <mask> <mask> This could be a file named :file:`autoapp.py` with these contents:: <mask> <mask> import o...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
flask create_user admin
<mask> application from an environment variable. <mask> <mask> This could be a file named :file:`autoapp.py` with these contents:: <mask> <mask> import os <mask> from yourapplication import create_app <mask> app = create_app(os.environ['YOURAPPLICATION_CONFIG']) <mask> <mask> Once this has happe...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
This example adds the same command, but as ``user create``, a command in a group. This is useful if you want to organize multiple related commands. ::
<mask> import os <mask> from yourapplication import create_app <mask> app = create_app(os.environ['YOURAPPLICATION_CONFIG']) <mask> <mask> Once this has happened you can make the :command:`flask` command automatically <mask> pick it up:: <mask> <mask> export YOURAPPLICATION_CONFIG=/path/to/con...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
import click from flask import Flask from flask.cli import AppGroup app = Flask(__name__) user_cli = AppGroup('user') @user_cli.command('create') @click.argument('name') def create_user(name): ... app.cli.add_command(user_cli) :: flask user create demo Application ...
<mask> <mask> Once this has happened you can make the :command:`flask` command automatically <mask> pick it up:: <mask> <mask> export YOURAPPLICATION_CONFIG=/path/to/config.cfg <mask> export FLASK_APP=/path/to/autoapp.py <mask> <mask> From this point onwards :command:`flask` will find your applicatio...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
<mask> <mask> export YOURAPPLICATION_CONFIG=/path/to/config.cfg <mask> export FLASK_APP=/path/to/autoapp.py <mask> <mask> From this point onwards :command:`flask` will find your application. <mask> <mask> .. _custom-scripts: <mask> <mask> Custom Scripts <mask> -------------- </s> rewrite cli docs...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
When you are using the app factory pattern, it may be more convenient to define your own Click script. Instead of using ``FLASK_APP`` and letting Flask load your application, you can create your own Click object and export it as a `console script`_ entry point. Create an instance of :class:`~cli.FlaskGroup` and pass i...
<mask> <mask> Custom Scripts <mask> -------------- <mask> <mask> While the most common way is to use the :command:`flask` command, you can <mask> also make your own "driver scripts". Since Flask uses click for the <mask> scripts there is no reason you cannot hook these scripts into any click <mask> applicati...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "re...
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
from flask import Flask
<mask> Create an instance of :class:`~cli.FlaskGroup` and pass it the factory:: <mask> <mask> import click <mask> from flask.cli import FlaskGroup <mask> <mask> def create_app(): <mask> app = Flask('wiki') <mask> # other setup </s> rewrite cli docs reflects the current FLASK_APP d...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
def create_app(): app = Flask('wiki') # other setup return app
<mask> import os <mask> import click <mask> from flask.cli import FlaskGroup <mask> <mask> def create_wiki_app(info): <mask> from yourwiki import create_app <mask> return create_app( <mask> config=os.environ.get('WIKI_CONFIG', 'wikiconfig.py')) <mask> <mask> @...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
@click.group(cls=FlaskGroup, create_app=create_app)
<mask> from yourwiki import create_app <mask> return create_app( <mask> config=os.environ.get('WIKI_CONFIG', 'wikiconfig.py')) <mask> <mask> @click.group(cls=FlaskGroup, create_app=create_wiki_app) <mask> def cli(): <mask> """This is a management script for the wiki a...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
"""Management script for the Wiki application.""" Define the entry point in :file:`setup.py`::
<mask> config=os.environ.get('WIKI_CONFIG', 'wikiconfig.py')) <mask> <mask> @click.group(cls=FlaskGroup, create_app=create_wiki_app) <mask> def cli(): <mask> """This is a management script for the wiki application.""" <mask> <mask> if __name__ == '__main__': <mask> cli(...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "re...
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
..., entry_points={ 'console_scripts': [ 'wiki=wiki:cli' ], },
<mask> from setuptools import setup <mask> <mask> setup( <mask> name='flask-my-extension', <mask> ... <mask> entry_points=''' <mask> [flask.commands] <mask> my-command=mypackage.commands:cli <mask> ''', <mask> ) <mask> <mask> Inside :file...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
Install the application in the virtualenv in editable mode and the custom script is available. Note that you don't need to set ``FLASK_APP``. ::
<mask> my-command=mypackage.commands:cli <mask> ''', <mask> ) <mask> <mask> Inside :file:`mypackage/commands.py` you can then export a Click object:: <mask> <mask> import click <mask> <mask> @click.command() <mask> def cli(): </s> rewrite cli docs reflects the current F...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
$ pip install -e . $ wiki run
<mask> ) <mask> <mask> Inside :file:`mypackage/commands.py` you can then export a Click object:: <mask> <mask> import click <mask> <mask> @click.command() <mask> def cli(): <mask> """This is an example command.""" <mask> </s> rewrite cli docs reflects the current FLASK_APP detecti...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
.. _console script: https://packaging.python.org/tutorials/distributing-packages/#console-scripts
<mask> Inside :file:`mypackage/commands.py` you can then export a Click object:: <mask> <mask> import click <mask> <mask> @click.command() <mask> def cli(): <mask> """This is an example command.""" <mask> <mask> Once that package is installed in the same virtualenv as Flask itself you <...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
You can skip this next step if you're using :ref:`dotenv`. We need to add an environment variable (**C**) to identify our application. Click on the browse button and add an entry with ``FLASK_APP`` on the left and the name of the Python file or package on the right (``app.py`` for example).
<mask> <mask> The *Script Parameter* field (**B**) is set to the cli command you wish to <mask> execute, in this example we use ``run`` which will run our development server. <mask> <mask> We need to add an environment variable (**C**) to identify our application. <mask> Click on the browse button and add an en...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/cli.rst
* `Watchdog`_ provides a faster, more efficient reloader for the development server.
<mask> Python's ``json`` module. It is preferred for JSON operations if it is <mask> installed. <mask> * `python-dotenv`_ enables support for :ref:`dotenv` when running ``flask`` <mask> commands. <mask> <mask> .. _Blinker: https://pythonhosted.org/blinker/ <mask> .. _SimpleJSON: https://simplejson.readthe...
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/installation.rst
.. _watchdog: https://pythonhosted.org/watchdog/
<mask> <mask> .. _Blinker: https://pythonhosted.org/blinker/ <mask> .. _SimpleJSON: https://simplejson.readthedocs.io/ <mask> .. _python-dotenv: https://github.com/theskumar/python-dotenv#readme <mask> <mask> Virtual environments <mask> -------------------- <mask> </s> rewrite cli docs reflects the current ...
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
docs/installation.rst
version_option = click.Option( ['--version'], help='Show the flask version', expose_value=False, callback=get_version, is_flag=True, is_eager=True )
<mask> 'python_version': sys.version, <mask> }, color=ctx.color) <mask> ctx.exit() <mask> <mask> version_option = click.Option(['--version'], <mask> help='Show the flask version', <mask> expose_value=False, <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
flask/cli.py
A general utility script for Flask applications.
<mask> click.echo(row.format(rule.endpoint, methods, rule.rule).rstrip()) <mask> <mask> <mask> cli = FlaskGroup(help="""\ <mask> This shell command acts as general utility script for Flask applications. <mask> <mask> It loads the application configured (through the FLASK_APP environment <mask> variab...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
flask/cli.py
Provides commands from Flask, extensions, and the application. Loads the application defined in the FLASK_APP environment variable, or from a wsgi.py file. Debug mode can be controlled with the FLASK_DEBUG environment variable.
<mask> Flask itself. <mask> <mask> The most useful commands are the "run" and "shell" command. <mask> <mask> Example usage: <mask> <mask> \b <mask> %(prefix)s%(cmd)s FLASK_APP=hello.py <mask> %(prefix)s%(cmd)s FLASK_DEBUG=1 <mask> %(prefix)sflask run </s> rewrite cli docs reflects the current FLASK_...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
flask/cli.py
{prefix}{cmd} FLASK_APP=hello.py {prefix}{cmd} FLASK_DEBUG=1 {prefix}flask run """.format( cmd='export' if os.name == 'posix' else 'set', prefix='$ ' if os.name == 'posix' else '> ' ))
<mask> <mask> Example usage: <mask> <mask> \b <mask> %(prefix)s%(cmd)s FLASK_APP=hello.py <mask> %(prefix)s%(cmd)s FLASK_DEBUG=1 <mask> %(prefix)sflask run <mask> """ % { <mask> 'cmd': os.name == 'posix' and 'export' or 'set', <mask> 'prefix': os.name == 'posix' and '$ ' or '', <mask> }) <ma...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bc329c0c9dcdb5a3a6919f31542b6e7453d8aa8
flask/cli.py
This is always called, even if an error happened. An `exc` keyword argument is passed with the exception that caused the teardown. .. versionchanged:: 0.9 The `exc` parameter was added. .. data:: appcontext_tearing_down This signal is sent when the application is tearing down the application co...
<mask> <mask> .. data:: request_tearing_down <mask> <mask> This signal is sent when the application is tearing down the request. <mask> This is always called, even if an error happened. No arguments are <mask> provided. <mask> <mask> .. currentmodule:: None <mask> <mask> .. class:: flask.signals...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bed20c07c40a163077b936f740a4e96a6213688
docs/api.rst
appcontext
<mask> signals <mask> views <mask> reqcontext <mask> blueprints <mask> extensions <mask> shell </s> Added documentation for appcontext and teardown handlers </s> remove Using _request_ctx_stack ------------------------ </s> add As you noticed, ``init_app`` does not assign ``app`` to ``self`...
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bed20c07c40a163077b936f740a4e96a6213688
docs/contents.rst.inc
What's important about classes is that they encourage to be shared around on module level. In that case, the object itself must not under any circumstances store any application specific state and must be shareable between different application.
<mask> we will use the class-based approach because it will provide users with an <mask> object that handles opening and closing database connections. <mask> <mask> The Extension Code <mask> ------------------ <mask> <mask> Here's the contents of the `flask_sqlite3.py` for copy/paste:: </s> Added documentatio...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bed20c07c40a163077b936f740a4e96a6213688
docs/extensiondev.rst
# Find the stack on which we want to store the database connection. # Starting with Flask 0.9, the _app_ctx_stack is the correct one, # before that we need to use the _request_ctx_stack. try: from flask import _app_ctx_stack as stack except ImportError: from flask import _request_ctx...
<mask> Here's the contents of the `flask_sqlite3.py` for copy/paste:: <mask> <mask> import sqlite3 <mask> <mask> from flask import _request_ctx_stack <mask> <mask> <mask> class SQLite3(object): <mask> <mask> def __init__(self, app=None): </s> Added documentation for appcontext and te...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bed20c07c40a163077b936f740a4e96a6213688
docs/extensiondev.rst
ctx = stack.top
<mask> ctx.sqlite3_db.close() <mask> <mask> @property <mask> def connection(self): <mask> ctx = _request_ctx_stack.top <mask> if ctx is not None: <mask> return ctx.sqlite3_db <mask> <mask> <mask> So here's what these lines of code do: </s...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/9bed20c07c40a163077b936f740a4e96a6213688
docs/extensiondev.rst