Our blog now has implemented a view of blog list, blog view. Now it's time for us to create and update blogs.To create and update your blog, we need to learn about Django forms.What does the Django form function do during the process of working with the form?
Preparation and reconstruction of data transfer
Create an HTML form for your data
Receive and process submitted
Field.nullThe default is Null=false, where null data cannot be passed in, but it can be a null character.If you want a null data type in Booleanfield, you can choose NullbooleanfieldField.blankThe default value is Blank=false, which means that the default is not allowed to be empty, and how to blank=true the default value can be empty.The constraint for a field can be blank=true or false, and it can be either null=ture or false.This article is for bloggers original articles, reproduced please in
route to the urls.py file= [ # 以上还有很多url路由,这里仅列出需要的路由 # 添加成功后返回添加成功页面addok url(r‘^addok/‘, polls_views.addok),]Create a new addok.html file in the Templates directory and add the HTML code.HTML code:Html>lang="en"> charset="UTF-8"> Add success Add book success href="/addbook/">Continue to add href="/booklist/">View List of Books The display results are as follows:
Pass booklist.html page when user clicks "View book list"
Booklist.html
Person.objects.filter (name__icontains= "abc") #名称中包含 "ABC", and ABC is case insensitive Person.objects.filter (name__regex= "^ABC") # Regular expression query Person.objects.filter (name__iregex= "^ABC") # Regular expressions are case-insensitive # Filter is found to meet the conditions, of course, there are also excluded Person.objects.exclude (name__contains= "wz") # Exclude the Person object containing WZ Person.objects.filter ( name__contains= "ABC"). Exclude (AGE=23) # Find out the name c
The form also has nothing to say, I only give an example of everyone to understandForm model from Import Forms class UserForm (forms. Form): = forms. Charfield (label='UserName', max_length=100) = forms. Charfield (label='Password', max_length=20, widget=forms. Passwor
Code in views.py:1 fromDjango.httpImportHttpResponse2 fromDjango.shortcutsImportRender_to_response3 fromDjangoImportForms4 5 classUserForm (forms. Form):6Name =forms. Charfield ()7 8 defRegister (req):9 ifReq.method = ="POST":Ten #Binding of Form objects Oneform =UserForm (req. POST) A #Validation of data - ifform.is_valid (): - #access to Data the Prin
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.