blob: 1caf2563de426430c6e8e22e4fdc02fd3e6b3a6f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
Slide 1 [00:08 | 00:08]
------------
Title Slide
**Creating Forms to edit the Blog**
Slide 2 [00:12 | 00:20]
--------------
**Learning Objectives**
In this tutorial, we will learn to;
- Create a new form
- Create a new view to handle form submission
Slide 3 [00:11 | 00:31]
---------------
**System Requirements**
- Ubuntu 16.10
- Python 3.5 or higher version
- python3.4-venv
Slide 4:
----------------
**What is a Form?**
- In HTML, a form is a collection of elements inside <form>...</form>
- Allow a visitor to do things like;
- enter text
- select options
- manipulate objects or controls, and so on,
- Send information back to the server
Slide 5
----------------
**Django Forms**
- Django provides inbuilt libraries to help you build forms easily
Slide 6
-----------------
**What is POST Request**
- A form is what the user sees when the application is storing new *or* updating/deleting existing data on a server,
- In the backend this storage, updation or deletion is done using a POST request
- A POST request method requests that a web server accept the data enclosed in the body of the request message
Slide 7
----------------
**Creating a New Form for Blogs**
- Create a forms.py in the ```blog``` and add the code
class BlogForm(ModelForm):
class Meta:
model = Blog
fields = ['name', 'created_on']
class ArticleForm(ModelForm):
class Meta:
model = Article
fields = ['created_on', 'title', 'body', 'draft']
Slide 8
----------------
**Adding a new view to handle the form**
Slide 7
-----------------
**Creating an HTML Form**
Slide 8
-----------------
**Creating a Template for the view**
Slide 9
-----------------
**Testing the new view and form**
|