Django

Django Forms

Form classes, ModelForm, validation, custom validators, form widgets, formsets, crispy forms

22 câu hỏi phỏng vấn·
Mid-Level
1

Which base class should be used to create a simple Django form (not tied to a model)?

Câu trả lời

The forms.Form class is the base class for creating Django forms independent of any model. It allows manually defining each field with its type and validators. ModelForm is only used when binding the form directly to an existing Django model.

2

How to access validated data from a Django form after calling is_valid()?

Câu trả lời

The cleaned_data attribute is a dictionary containing form data after validation and cleaning. It is only available after a successful call to is_valid(). Values are converted to appropriate Python types (for example, a date string becomes a datetime.date object).

3

In a ModelForm, which Meta class attribute specifies the model to use?

Câu trả lời

The model attribute in a ModelForm's Meta class defines the Django model the form will be based on. Django automatically generates form fields corresponding to the specified model's fields. The fields or exclude attributes then control which fields to include.

4

Which method validates a specific field in a Django form?

5

Which method should be used to validate multiple interdependent fields in a Django form?

+19 câu hỏi phỏng vấn

Nắm vững Django cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí