Skip to content

Instantly share code, notes, and snippets.

@vrslev
Last active September 15, 2025 02:36
Show Gist options
  • Select an option

  • Save vrslev/6d0602bfa939a01844f645c608afb85a to your computer and use it in GitHub Desktop.

Select an option

Save vrslev/6d0602bfa939a01844f645c608afb85a to your computer and use it in GitHub Desktop.

Revisions

  1. vrslev revised this gist Dec 20, 2023. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions main.py
    Original file line number Diff line number Diff line change
    @@ -21,6 +21,4 @@ def index(request: Request):
    return templates.TemplateResponse("index.html", context={"request": request})

    # run:
    # DEBUG=true uvicorn main:app --reload
    #
    # P. S. I guess, it doesn't work in Safari.
    # DEBUG=true uvicorn main:app --reload
  2. vrslev revised this gist Oct 24, 2023. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions main.py
    Original file line number Diff line number Diff line change
    @@ -22,3 +22,5 @@ def index(request: Request):

    # run:
    # DEBUG=true uvicorn main:app --reload
    #
    # P. S. I guess, it doesn't work in Safari.
  3. vrslev revised this gist Nov 30, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions main.py
    Original file line number Diff line number Diff line change
    @@ -19,3 +19,6 @@
    @app.get("/")
    def index(request: Request):
    return templates.TemplateResponse("index.html", context={"request": request})

    # run:
    # DEBUG=true uvicorn main:app --reload
  4. vrslev created this gist Jan 5, 2022.
    21 changes: 21 additions & 0 deletions main.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    import os

    import arel
    from fastapi import FastAPI, Request
    from fastapi.templating import Jinja2Templates

    app = FastAPI()
    templates = Jinja2Templates("templates")

    if _debug := os.getenv("DEBUG"):
    hot_reload = arel.HotReload(paths=[arel.Path(".")])
    app.add_websocket_route("/hot-reload", route=hot_reload, name="hot-reload")
    app.add_event_handler("startup", hot_reload.startup)
    app.add_event_handler("shutdown", hot_reload.shutdown)
    templates.env.globals["DEBUG"] = _debug
    templates.env.globals["hot_reload"] = hot_reload


    @app.get("/")
    def index(request: Request):
    return templates.TemplateResponse("index.html", context={"request": request})
    4 changes: 4 additions & 0 deletions requirements.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    fastapi
    uvicorn[standard]
    arel
    jinja2
    7 changes: 7 additions & 0 deletions templates-base.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    <body>
    {% block content %}{% endblock %}

    <!-- Hot reload script -->
    {% if DEBUG %} {{ hot_reload.script(url_for('hot-reload')) | safe }} {% endif
    %}
    </body>
    1 change: 1 addition & 0 deletions templates-index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    {% extends "base.html" %} {% block content %} Hello, world! {% endblock %}