forked from litestar-org/litestar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from litestar-org/flash-1
docs: add more documentation
- Loading branch information
Showing
9 changed files
with
117 additions
and
26 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from litestar import Litestar | ||
from litestar.contrib.jinja import JinjaTemplateEngine | ||
from litestar.plugins.flash import FlashConfig, FlashPlugin | ||
from litestar.template.config import TemplateConfig | ||
|
||
template_config = TemplateConfig(engine=JinjaTemplateEngine, directory="templates") | ||
flash_plugin = FlashPlugin(config=FlashConfig(template_config=template_config)) | ||
|
||
app = Litestar(plugins=[flash_plugin]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from litestar import Litestar | ||
from litestar.contrib.mako import MakoTemplateEngine | ||
from litestar.plugins.flash import FlashConfig, FlashPlugin | ||
from litestar.template.config import TemplateConfig | ||
|
||
template_config = TemplateConfig(engine=MakoTemplateEngine, directory="templates") | ||
flash_plugin = FlashPlugin(config=FlashConfig(template_config=template_config)) | ||
|
||
app = Litestar(plugins=[flash_plugin]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from litestar import Litestar | ||
from litestar.contrib.minijinja import MiniJinjaTemplateEngine | ||
from litestar.plugins.flash import FlashConfig, FlashPlugin | ||
from litestar.template.config import TemplateConfig | ||
|
||
template_config = TemplateConfig(engine=MiniJinjaTemplateEngine, directory="templates") | ||
flash_plugin = FlashPlugin(config=FlashConfig(template_config=template_config)) | ||
|
||
app = Litestar(plugins=[flash_plugin]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from litestar import Litestar, Request, get | ||
from litestar.contrib.jinja import JinjaTemplateEngine | ||
from litestar.plugins.flash import FlashConfig, FlashPlugin, flash | ||
from litestar.response import Template | ||
from litestar.template.config import TemplateConfig | ||
|
||
template_config = TemplateConfig(engine=JinjaTemplateEngine, directory="templates") | ||
flash_plugin = FlashPlugin(config=FlashConfig(template_config=template_config)) | ||
|
||
|
||
@get() | ||
async def index(request: Request) -> Template: | ||
"""Example of adding and displaying a flash message.""" | ||
flash(request, "Oh no! I've been flashed!", category="error") | ||
|
||
return Template( | ||
template_str=""" | ||
<h1>Flash Message Example</h1> | ||
{% for message in get_flashes() %} | ||
<p>{{ message.message }} (Category:{{ message.category }})</p> | ||
{% endfor %} | ||
""" | ||
) | ||
|
||
|
||
app = Litestar(plugins=[flash_plugin], route_handlers=[index], template_config=template_config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
===== | ||
flash | ||
===== | ||
|
||
|
||
.. automodule:: litestar.plugins.flash | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
======= | ||
plugins | ||
======= | ||
|
||
|
||
.. automodule:: litestar.plugins | ||
:members: | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
flash_messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters