ΕργασίαBuild the signup form matching the Pydantic Signup schema. Use a <form method='post' action='/api/signup'>. Inside one <fieldset><legend>Account</legend>: email + password. Second <fieldset><legend>Profile</legend>: age, country select (us/ua/de), bio textarea, accepted_tos checkbox. End with a submit button. Use labels, autocomplete, and validation attributes throughout.
Επικεφαλίδα ενότητας: φόρμα εγγραφής που ταιριάζει με ένα σχήμα Pydantic
200 XP14 min
Θεωρία
Putting A3 together
Your FastAPI endpoint:
class Signup(BaseModel):
email: EmailStr
password: str = Field(min_length=8)
age: int = Field(ge=13, le=120)
country: Literal["us", "ua", "de"]
bio: str = Field(default="", max_length=500)
accepted_tos: bool
@app.post("/api/signup")
async def signup(data: Annotated[Signup, Form()]):
return dataYour job: build the HTML form whose request body matches this schema 1:1. Field names match. Validation matches. autocomplete hints are set. Labels are linked. Group into fieldsets.
What "matches" means
- For
email: EmailStr→<input type="email" name="email" required autocomplete="email"> - For
password: Field(min_length=8)→<input type="password" name="password" required minlength="8" autocomplete="new-password"> - For
age: Field(ge=13, le=120)→<input type="number" name="age" required min="13" max="120"> - For
country: Literal["us", "ua", "de"]→<select name="country" required>with those three options - For
bio: Field(max_length=500)→<textarea name="bio" maxlength="500">(NOT required since default="") - For
accepted_tos: bool→<input type="checkbox" name="accepted_tos" value="yes" required>
This is the API contract first mindset that the rest of A3 led up to.
🔒
Εγγράψου για να αρχίσεις να προγραμματίζεις
Η θεωρία είναι ανοιχτή για όλους. Ο επεξεργαστής, η ζωντανή προεπισκόπηση και ο έλεγχος ξεκλειδώνουν με 7-ήμερη δωρεάν δοκιμή — απαιτείται κάρτα.
Εγγραφή — δωρεάν δοκιμή →Τα πρώτα 10 μαθήματα κάθε διαδρομής είναι δωρεάν. Δεν χρειάζεται κάρτα.