Prejsť na hlavný obsah
← 📄 HTML & the platform·Modul A3 · Lekcia 1
ÚlohaBuild a login form: <form action='/api/login' method='post'> containing <input name='email' type='email'>, <input name='password' type='password'>, <button type='submit'>Log in</button>.

<form action method>: žiadosť, ktorú váš backend dostane

75 XP8 min
Teória

Three attributes shape the HTTP request

<form action="/api/signup" method="post" enctype="application/x-www-form-urlencoded">
  <input name="email" type="email" />
  <input name="password" type="password" />
  <button type="submit">Sign up</button>
</form>
  • `action` — where the form POSTs. Relative or absolute URL. Defaults to the current page.
  • `method` — get (default, params in URL) or post (body). For mutations, use post. For searches, use get.
  • `enctype` — only matters for POST:

- application/x-www-form-urlencoded (default) — email=anna%40example.com&password=…

- multipart/form-data — required when one or more inputs are <input type="file">

- text/plain — never use this, it's only for debugging

What FastAPI sees

For <form method="post"><input name="email" value="anna@example.com"></form>, your FastAPI endpoint:

@app.post("/api/signup")
async def signup(email: str = Form()):
    return {"got": email}

The name="email" is the Pydantic field name. If you change name="user_email" on the input, FastAPI's Form(alias="user_email") is what catches it.

GET vs POST visibility

get puts data in the URL (/search?q=python) — bookmarkable, sharable, in browser history. post puts data in the body — invisible in URL, not in history, not bookmarked. Passwords ALWAYS POST.

🔒

Zaregistruj sa a začni programovať

Teória je otvorená pre každého. Editor, živý náhľad a kontrola sa odomknú so 7-dňovou bezplatnou skúškou — karta potrebná, zruš kedykoľvek.

Registrácia — bezplatná skúška →

Prvých 10 lekcií v každej trase je zdarma. Karta nie je potrebná.

← PredchádzajúcaĎalšia lekcia →

Jeden tip k Pythonu alebo webu denne — e-mailom

Krátke, ručne písané, žiadny spam. Odhlásiť jedným klikom.