You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2.1 KiB

📄

👆 💪 ⚙️ 🙆 📄 🚒 👆 💚 ⏮️ FastAPI.

⚠ ⚒ Jinja2️⃣, 🎏 1️⃣ ⚙️ 🏺 & 🎏 🧰.

📤 🚙 🔗 💪 👈 👆 💪 ⚙️ 🔗 👆 FastAPI 🈸 (🚚 💃).

🔗

jinja2:

$ pip install jinja2

---> 100%

⚙️ Jinja2Templates

  • 🗄 Jinja2Templates.
  • templates 🎚 👈 👆 💪 🏤-⚙️ .
  • 📣 Request 🔢 🛠️ 👈 🔜 📨 📄.
  • ⚙️ templates 👆 ✍ ✍ & 📨 TemplateResponse, 🚶‍♀️ request 1️⃣ 🔑-💲 👫 Jinja2️⃣ "🔑".

{* ../../docs_src/templates/tutorial001.py hl[4,11,15:18] *}

/// note

👀 👈 👆 ✔️ 🚶‍♀️ request 🍕 🔑-💲 👫 🔑 Jinja2️⃣. , 👆 ✔️ 📣 👆 🛠️.

///

/// tip

📣 response_class=HTMLResponse 🩺 🎚 🔜 💪 💭 👈 📨 🔜 🕸.

///

/// note | 📡

👆 💪 ⚙️ from starlette.templating import Jinja2Templates.

FastAPI 🚚 🎏 starlette.templating fastapi.templating 🏪 👆, 👩‍💻. 🌅 💪 📨 👟 🔗 ➡️ 💃. 🎏 ⏮️ Request & StaticFiles.

///

📄

⤴️ 👆 💪📄 templates/item.html ⏮️:

{!../../docs_src/templates/templates/item.html!}

🔜 🎦 id ➡️ "🔑" dict 👆 🚶‍♀️:

{"request": request, "id": id}

📄 & 🎻 📁

& 👆 💪 ⚙️ url_for() 🔘 📄, & ⚙️ ️, 🖼, ⏮️ StaticFiles 👆 📌.

{!../../docs_src/templates/templates/item.html!}

👉 🖼, 🔜 🔗 🎚 📁 static/styles.css ⏮️:

{!../../docs_src/templates/static/styles.css!}

& ↩️ 👆 ⚙️ StaticFiles, 👈 🎚 📁 🔜 🍦 🔁 👆 FastAPI 🈸 📛 /static/styles.css.

🌅

🌅 ℹ, 🔌 💯 📄, 💃 🩺 🔛 📄.