Forms Flashcards
What does the action attribute in a <form> specify?
The URL where the form data will be sent after submission.
What is the purpose of the method attribute in a <form>?
Specifies how to send the form data (GET for retrieving data, POST for submitting changes).
What is the role of the id attribute in an <input> element?
Provides a unique identifier for the input, often used with <label> for accessibility.</label>
How is the name attribute used in an <input></input> element?
Specifies the key that will pair with the input value when form data is submitted.
What does the disabled attribute do in an <input></input> element?
Prevents the input from being edited or submitted.
What does the value attribute do in an <input> element?
Sets the default value of the input field.
How does the required attribute work in an <input></input> element?
Forces the user to fill out the input before submitting the form.
What do the min and max attributes do in an <input></input> element?
Set the numeric or date range allowed for the input.
What do the minlength and maxlength attributes do in an <input></input> element?
Define the minimum and maximum number of characters allowed.
What does the accept attribute in an <input> element do?
Specifies the file types allowed when the input type is file.
How can you style valid or invalid input fields using CSS?
Use :valid and :invalid pseudo-classes.
Write an input element that requires a number between 1 and 10.
<input type=”number” min=”1” max=”10” required>
How would you make a text input required with a maximum of 50 characters?
<input type=”text” required maxlength=”50”>
How do you access form data submitted via POST in a Django view?
Use request.POST.
How do you handle file uploads in a Django view?
Use request.FILES to access the uploaded file.
How do you catch ValueError when parsing numbers in Django?
Use a try-except block.
How do you catch DoesNotExist errors in Django?
Use a try-except block and raise Http404 if the object isn’t found.
What are some risks of handling file uploads in web applications?
- Large files may consume server storage or memory.
2.Malicious files may execute harmful code.
- Files might overwrite existing files.
- Files might masquerade as safe types (e.g., .jpg but actually executable).
- Improper permissions may expose uploaded files to unauthorized access.
When should you use GET for form submission?
Use GET for requests that don’t change server state, such as search forms.
When should you use POST for form submission?
Use POST for requests that create, update, or delete data.
How do you describe a simple security policy?
By specifying which users can perform which actions (e.g., “Only admins can delete users”).
Define authentication.
The process of verifying a user’s identity (e.g., via a username and password).
Define authorization.
The process of determining what actions an authenticated user is allowed to perform.
What is the purpose of a cookie in web security?
A cookie stores data in the user’s browser, often used to maintain session identity.
How do sessions work with cookies for user logins?
After login, the server generates a session ID, stores it in a cookie, and uses it to track the user’s state across requests.