mirror of
https://github.com/fastapi/fastapi.git
synced 2026-05-18 13:27:45 -04:00
📝 Add documentation about settings and env vars (#1118)
* Add doc and example for env var config * Syntax highlight for .env file * Add test for configuration docs * 📝 Update settings docs, add more examples * ✅ Add tests for settings * 🚚 Rename "Application Configuration" to "Metadata and Docs URLs" to disambiguate between that and settings * 🔥 Remove replaced example file Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
21
docs_src/settings/tutorial001.py
Normal file
21
docs_src/settings/tutorial001.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseSettings
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
app_name: str = "Awesome API"
|
||||
admin_email: str
|
||||
items_per_user: int = 50
|
||||
|
||||
|
||||
settings = Settings()
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/info")
|
||||
async def info():
|
||||
return {
|
||||
"app_name": settings.app_name,
|
||||
"admin_email": settings.admin_email,
|
||||
"items_per_user": settings.items_per_user,
|
||||
}
|
||||
Reference in New Issue
Block a user