1 / 12

Training django Form

VIDA. Training django Form. I- FORM. 1) Giới thiệu : Dùng thư viện form của django ta có thể : Sinh form tự động từ wigets Validate data thông qua validation rules Hiển thị lại form trong trường hợp validate error Chuyển dữ liệu trong form sang python datatype. I- FORM.

Télécharger la présentation

Training django Form

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. VIDA Training djangoForm

  2. I- FORM • 1) Giớithiệu: • Dùngthưviện form củadjango ta cóthể: • Sinhform tựđộngtừwigets • Validate data thôngqua validation rules • Hiểnthịlại form trongtrườnghợp validate error • Chuyểndữliệutrong form sang python datatype

  3. I- FORM • 2) Khaibáo: • Djangocungcấp 2 đốitượng form: • Form thường • Import: from django import forms • Tạo form: class ContactForm(forms.Form) • Tạo filed: name_field_form = forms.FieldType(param1, param2…) • Sửdụng function clean_<name_field_form> nếumuốn validate thêmcho field đó

  4. I- FORM • 2) Khaibáo: • Djangocungcấp 2 đốitượng form: • ModelForm: (Djangocungcấpđốitượngmodelformđểtậndụngkhaibáotừ model) • Import: from django.forms import ModelForm • Tạo form: class <tên Form>(ModelForm ), trong class Form khaibáothêm class meta chỉrõ mode = <ten model thamchieu>

  5. I- FORM • 3) Sửdụng: • Tạo file forms.py • Import thưviện • Khaibáo form, field • Set rule

  6. I- FORM • 1) Sửdụng: • Validate rule: • Sửdụngfunction clean_<ten field> đểvalidate chochính field đượcxét, nếucólỗisẽđược output thông qua forms.ValidationError

  7. I- FORM • 3) Sửdụng: • Sửdụng form trong views.py • Tạo instance form • Check valid

  8. I- FORM • 3) Sửdụng: • Sửdụng form trong template • form.as_psẽsinh form bằngthẻ <p> • Form.as_tablesẽsinh form trongthẻ <table> • Cóthể custom lại form trong template

  9. I- FORM • 3) Sửdụng: • Sửdụng form trong template • Custom:

  10. I- FORM • 3) Sửdụng: • Fieldtypesửdụngtrong form: • BooleanField (CheckboxInput) • CharField(TextInput) • ChoiceField(Select) • TypedChoiceField( Select) • DateField(DateInput) • DateTimeField(DateTimeInput) • DecimalField(TextInput) • EmailField( TextInput) • FileFiled(ClearableFileInput) • FilePathField( Select) • FloatField( TextInput) • ImageField( ClearableFileInput)

  11. I- FORM • 3) Sửdụng: • Fieldtypesửdụngtrong form: • IntegerField(TextInput) • IPAddressField(TextInput) • GenericIPAddressField(TextInput) • MultipleChoiceField(SelectMultiple) • TypedMultipleChoiceField(SelectMultiple) • NullBooleanField(NullBooleanSelect) • RegexField(TextInput ) • SlugField(TextInput) • TimeField(TextInput) • URLField(TextInput) • ComboField(TextInput) • MultiValueField(TextInput)

  12. I- FORM • 3) Sửdụng: • Fieldtypesửdụngtrong form: • SplitDateTimeField(SplitDateTimeWidget) • ModelChoiceField(Select) • ModelMultipleChoiceField(SelectMultiple)

More Related