297 lines
13 KiB
HTML
297 lines
13 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Quart-Imp Introduction | Quart-Imp</title>
|
|
<link rel="stylesheet" href="static/water.css">
|
|
<link rel="stylesheet" href="static/pygments.emacs-dull.css">
|
|
<link rel="apple-touch-icon" sizes="180x180" href="static/apple-touch-icon.png">
|
|
<link rel="icon" type="image/png" sizes="32x32" href="static/favicon-32x32.png">
|
|
<link rel="icon" type="image/png" sizes="16x16" href="static/favicon-16x16.png">
|
|
<link rel="manifest" href="static/site.webmanifest">
|
|
<link rel="mask-icon" href="static/safari-pinned-tab.svg" color="#5bbad5">
|
|
<meta name="msapplication-TileColor" content="#da532c">
|
|
<meta name="theme-color" content="#ffffff">
|
|
</head>
|
|
<body>
|
|
|
|
<aside>
|
|
<img src="static/quart-Imp-Medium.png" alt="Quart-Imp Logo" style="margin-top: 20px; width: 50%">
|
|
<h1>Quart-Imp</h1>
|
|
<div><small>Version: 1.0.x</small></div>
|
|
<div><small>Last Updated:</small></div>
|
|
<div><small>Fri, 16 Aug 2024</small></div>
|
|
<h2>Menu</h2>
|
|
<ul>
|
|
<li><a href="index.html"><strong>Index</strong></a></li>
|
|
</ul>
|
|
<ul>
|
|
|
|
|
|
<li><strong>CLI Commands</strong></li>
|
|
|
|
|
|
<ul>
|
|
|
|
|
|
<li><a href="cli_commands-quart-imp_init.html">quart-imp init</a></li>
|
|
|
|
|
|
|
|
<li><a href="cli_commands-quart-imp_blueprint.html">quart-imp blueprint</a></li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<li><strong>Imp</strong></li>
|
|
|
|
|
|
<ul>
|
|
|
|
|
|
<li><a href="imp-introduction.html">Introduction</a></li>
|
|
|
|
|
|
|
|
<li><a href="imp-init_app-init.html">init_app, __init__</a></li>
|
|
|
|
|
|
|
|
<li><a href="imp-init_session.html">init_session</a></li>
|
|
|
|
|
|
|
|
<li><a href="imp-import_app_resources.html">import_app_resources</a></li>
|
|
|
|
|
|
|
|
<li><a href="imp-import_blueprint.html">import_blueprint</a></li>
|
|
|
|
|
|
|
|
<li><a href="imp-import_blueprints.html">import_blueprints</a></li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<li><strong>ImpBlueprint</strong></li>
|
|
|
|
|
|
<ul>
|
|
|
|
|
|
<li><a href="impblueprint-introduction.html">Introduction</a></li>
|
|
|
|
|
|
|
|
<li><a href="impblueprint-init.html">__init__</a></li>
|
|
|
|
|
|
|
|
|
|
|
|
<li><a href="impblueprint-import_resources.html">import_resources</a></li>
|
|
|
|
|
|
|
|
<li><a href="impblueprint-import_nested_blueprint.html">import_nested_blueprint</a></li>
|
|
|
|
|
|
|
|
<li><a href="impblueprint-import_nested_blueprints.html">import_nested_blueprints</a></li>
|
|
|
|
|
|
|
|
<li><a href="impblueprint-tmpl.html">tmpl</a></li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<li><strong>quart_imp.config</strong></li>
|
|
|
|
|
|
<ul>
|
|
|
|
|
|
<li><a href="quart_imp_config-quartconfig.html">QuartConfig</a></li>
|
|
|
|
|
|
|
|
<li><a href="quart_imp_config-impconfig.html">ImpConfig</a></li>
|
|
|
|
|
|
|
|
<li><a href="quart_imp_config-impblueprintconfig.html">ImpBlueprintConfig</a></li>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<li><strong>quart_imp.security</strong></li>
|
|
|
|
|
|
<ul>
|
|
|
|
|
|
<li><a href="quart_imp_security-login_check.html">login_check</a></li>
|
|
|
|
|
|
|
|
<li><a href="quart_imp_security-permission_check.html">permission_check</a></li>
|
|
|
|
|
|
|
|
<li><a href="quart_imp_security-pass_function_check.html">pass_function_check</a></li>
|
|
|
|
|
|
|
|
<li><a href="quart_imp_security-api_login_check.html">api_login_check</a></li>
|
|
|
|
|
|
|
|
<li><a href="quart_imp_security-include_csrf.html">include_csrf</a></li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<li><strong>quart_imp.auth</strong></li>
|
|
|
|
|
|
<ul>
|
|
|
|
|
|
<li><a href="quart_imp_auth-encrypt_password.html">encrypt_password</a></li>
|
|
|
|
|
|
|
|
<li><a href="quart_imp_auth-authenticate_password.html">authenticate_password</a></li>
|
|
|
|
|
|
|
|
<li><a href="quart_imp_auth-generate_password.html">generate_password</a></li>
|
|
|
|
|
|
|
|
<li><a href="quart_imp_auth-generate_salt.html">generate_salt</a></li>
|
|
|
|
|
|
|
|
<li><a href="quart_imp_auth-generate_csrf_token.html">generate_csrf_token</a></li>
|
|
|
|
|
|
|
|
<li><a href="quart_imp_auth-generate_private_key.html">generate_private_key</a></li>
|
|
|
|
|
|
|
|
<li><a href="quart_imp_auth-generate_email_validator.html">generate_email_validator</a></li>
|
|
|
|
|
|
|
|
<li><a href="quart_imp_auth-generate_numeric_validator.html">generate_numeric_validator</a></li>
|
|
|
|
|
|
|
|
<li><a href="quart_imp_auth-generate_alphanumeric_validator.html">generate_alphanumeric_validator</a></li>
|
|
|
|
|
|
|
|
<li><a href="quart_imp_auth-is_email_address_valid.html">is_email_address_valid</a></li>
|
|
|
|
|
|
|
|
<li><a href="quart_imp_auth-is_username_valid.html">is_username_valid</a></li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
</ul>
|
|
|
|
<div style="padding-top: 5px; margin-bottom: 20px;"><small>Hosted on GitHub Pages.</small></div>
|
|
</aside>
|
|
|
|
<section>
|
|
<h1 style="font-size: 2.6rem; margin: 0;">Quart-Imp Introduction</h1>
|
|
<p>Quart-Imp is a Quart extension that provides auto import methods for various Quart resources. It will import
|
|
blueprints, and other resources. It uses the importlib module to achieve this.</p>
|
|
<p>Quart-Imp favors the application factory pattern as a project structure, and is opinionated towards using
|
|
Blueprints. However, you can use Quart-Imp without using Blueprints.</p>
|
|
<p>Here's an example of a standard Quart-Imp project structure:</p>
|
|
<div class="highlight"><pre><span></span>app/
|
|
├── blueprints/
|
|
│ ├── admin/...
|
|
│ ├── api/...
|
|
│ └── www/...
|
|
├── resources/
|
|
│ ├── filters/...
|
|
│ ├── context_processors/...
|
|
│ ├── static/...
|
|
│ └── templates/...
|
|
└── __init__.py
|
|
</pre></div>
|
|
<p>Here's an example of the <code>app/__init__.py</code> file:</p>
|
|
<div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">quart</span> <span class="kn">import</span> <span class="n">Quart</span>
|
|
<span class="kn">from</span> <span class="nn">quart_sqlalchemy</span> <span class="kn">import</span> <span class="n">SQLAlchemy</span>
|
|
<span class="kn">from</span> <span class="nn">quart_imp</span> <span class="kn">import</span> <span class="n">Imp</span>
|
|
<span class="kn">from</span> <span class="nn">quart_imp.config</span> <span class="kn">import</span> <span class="n">QuartConfig</span><span class="p">,</span> <span class="n">ImpConfig</span>
|
|
|
|
<span class="n">db</span> <span class="o">=</span> <span class="n">SQLAlchemy</span><span class="p">()</span>
|
|
<span class="n">imp</span> <span class="o">=</span> <span class="n">Imp</span><span class="p">()</span>
|
|
|
|
|
|
<span class="k">def</span> <span class="nf">create_app</span><span class="p">():</span>
|
|
<span class="n">app</span> <span class="o">=</span> <span class="n">Quart</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>
|
|
<span class="n">QuartConfig</span><span class="p">(</span>
|
|
<span class="n">secret_key</span><span class="o">=</span><span class="s2">"super_secret_key"</span><span class="p">,</span>
|
|
<span class="n">app_instance</span><span class="o">=</span><span class="n">app</span><span class="p">,</span>
|
|
<span class="p">)</span>
|
|
|
|
<span class="n">imp</span><span class="o">.</span><span class="n">init_app</span><span class="p">(</span><span class="n">app</span><span class="p">,</span> <span class="n">config</span><span class="o">=</span><span class="n">ImpConfig</span><span class="p">(</span>
|
|
<span class="n">init_session</span><span class="o">=</span><span class="p">{</span><span class="s2">"logged_in"</span><span class="p">:</span> <span class="kc">False</span><span class="p">},</span>
|
|
<span class="p">))</span>
|
|
<span class="n">imp</span><span class="o">.</span><span class="n">import_app_resources</span><span class="p">(</span><span class="s2">"resources"</span><span class="p">)</span>
|
|
<span class="n">imp</span><span class="o">.</span><span class="n">import_blueprints</span><span class="p">(</span><span class="s2">"blueprints"</span><span class="p">)</span>
|
|
|
|
<span class="n">db</span><span class="o">.</span><span class="n">init_app</span><span class="p">(</span><span class="n">app</span><span class="p">)</span>
|
|
|
|
<span class="k">return</span> <span class="n">app</span>
|
|
</pre></div>
|
|
<p>The Quart configuration can be loaded from any standard Quart configuration method, or from the <code>QuartConfig</code> class
|
|
shown above.</p>
|
|
<p>This class contains the standard Quart configuration options found in the Quart documentation.</p>
|
|
<p>The <code>ImpConfig</code> class is used to configure the <code>Imp</code> instance.</p>
|
|
<p>The <code>init_session</code> option of the <code>ImpConfig</code> class is used to set the initial session variables for the Quart app.
|
|
This happens before the request is processed.</p>
|
|
<p><code>ImpConfig</code> also has the ability to set <code>SQLALCHEMY_DATABASE_URI</code> and <code>SQLALCHEMY_BINDS</code></p>
|
|
<p>For more information about the configuration setting see
|
|
<a href="quart_imp_config-impconfig.html">quart_imp_config-impconfig.md</a>.</p>
|
|
<p><code>import_app_resources</code> will walk one level deep into the <code>resources</code> folder, and import
|
|
all <code>.py</code> files as modules.
|
|
It will also check for the existence of a <code>static</code> and <code>templates</code> folder, and register them with the Quart app.</p>
|
|
<p>There is a couple of options for <code>import_app_resources</code> to control what
|
|
is imported, see: <a href="imp-import_app_resources.html">Imp / import_app_resources</a></p>
|
|
<p><code>import_blueprints</code> expects a folder that contains many Blueprint as Python packages.
|
|
It will check each blueprint folder's <code>__init__.py</code> file for an instance of a Quart Blueprint or a
|
|
Quart-Imp Blueprint. That instant will then be registered with the Quart app.</p>
|
|
<p>See more about how importing blueprints work here: <a href="impblueprint-introduction.html">ImpBlueprint / Introduction</a></p>
|
|
|
|
</section>
|
|
|
|
</body>
|
|
</html> |