-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTutorial.html
226 lines (218 loc) · 50.5 KB
/
Tutorial.html
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome file</title>
<link rel="stylesheet" href="https://stackedit.io/style.css" />
</head>
<body class="stackedit">
<div class="stackedit__left">
<div class="stackedit__toc">
<ul>
<li><a href="#welcome-to-tutorial">Welcome to Tutorial!</a></li>
<li><a href="#django-rest-framework">Django-REST-framework</a>
<ul>
<li><a href="#setup">Setup</a></li>
<li><a href="#fiie-structure-and-explanation">FIie structure and explanation</a></li>
<li><a href="#models.py">Models.py</a></li>
<li><a href="#serializers.py">Serializers.py</a></li>
<li><a href="#views.py">views.py</a></li>
<li><a href="#urls.py">urls.py</a></li>
<li><a href="#admin.py">admin.py</a></li>
<li><a href="#test">Test</a></li>
<li><a href="#summary">Summary</a></li>
</ul>
</li>
<li><a href="#retrofit2">Retrofit2</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
</div>
<div class="stackedit__right">
<div class="stackedit__html">
<h1 id="welcome-to-tutorial">Welcome to Tutorial!</h1>
<p>Hi, this is a simple tutorial related to ARORA project. In this tutorial, you will learn about how to primarily use Django-REST-framework and Retrofit2.</p>
<h1 id="django-rest-framework">Django-REST-framework</h1>
<h2 id="setup">Setup</h2>
<p>Let’s start with Django-rest-framework. Before we get started, please make sure:</p>
<ol>
<li>
<p>You have a python3 on your machine. Though Python is cross-platform, I recommend you use Linux or Linux VM as your operating system.</p>
</li>
<li>
<p>You have installed Django and Django-rest-framework on your python. If you haven’t</p>
<blockquote>
<p>pip(pipenv) install django<br>
pip(pipenv) install djangorestframework</p>
</blockquote>
</li>
<li>
<p>Have created a Django Project properly. If you use Pycharm as your IDE, Things should be easy. If you do not use Pycharm, you can use</p>
<blockquote>
<p>django-admin startproject < YOUR_PROJECT_NAME > .</p>
</blockquote>
</li>
<li>
<p>Have started an application, example1.</p>
<blockquote>
<p>python3 <a href="http://manage.py">manage.py</a> startapp example1</p>
</blockquote>
</li>
<li>
<p>You have example1, example2 and rest_framework at <strong>INSTALLED_APPS</strong> list which is at <em>< root_dir>/ djangorest_example/setting.py</em> .</p>
<pre><code> INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'example1',
'rest_framework',
]
</code></pre>
</li>
</ol>
<p>Here is a <a href="https://wsvincent.com/django-rest-framework-tutorial/">tutorial</a> could be help at set-up.</p>
<h2 id="fiie-structure-and-explanation">FIie structure and explanation</h2>
<p>After we have done the set-up, the whole project should look like this.<br>
<img src="https://lh3.googleusercontent.com/CAbsN_SgS47Dvu1yrGXq6M68HYC0CsG8ET-WWknex3Qeukezihxp_NPHA59Mxm6B2GSCYJ0vRrY" alt="enter image description here"><br>
And don’t forget to create <a href="http://serializers.py">serializers.py</a> and <a href="http://urls.py">urls.py</a> manually under every application.</p>
<p>Now,<br>
Let’s take example1, one of our created application, as an example.</p>
<div class="mermaid"><svg xmlns="http://www.w3.org/2000/svg" id="mermaid-svg-Ns9DYAt7uk0D6MZv" width="100%" style="max-width: 526.2859344482422px;" viewBox="0 0 526.2859344482422 913.9855461120605"><g transform="translate(-12, -12)"><g class="output"><g class="clusters"></g><g class="edgePaths"><g class="edgePath" style="opacity: 1;"><path class="path" d="M72.04554007384345,467.78380985599955L135.8828125,126.98554611206055L177.34375,126.98554611206055" marker-end="url(#arrowhead31936)" style="fill:none"></path><defs><marker id="arrowhead31936" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M248.29070953520952,103.98554611206055L312.3671875,43L389.0570297241211,43" marker-end="url(#arrowhead31937)" style="fill:none"></path><defs><marker id="arrowhead31937" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M248.29070953520952,149.98554611206055L312.3671875,210.9710922241211L340.8437515258789,211.4710922241211" marker-end="url(#arrowhead31938)" style="fill:none"></path><defs><marker id="arrowhead31938" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M74.60352482340912,468.3423030263482L135.8828125,222.98554611206055L177.8671875,222.98554611206055" marker-end="url(#arrowhead31939)" style="fill:none"></path><defs><marker id="arrowhead31939" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M79.37288197120047,469.8259993189441L135.8828125,318.98554611206055L176.859375,318.98554611206055" marker-end="url(#arrowhead31940)" style="fill:none"></path><defs><marker id="arrowhead31940" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M90.30850888395992,475.810683815319L135.8828125,414.98554611206055L187.3203125,414.98554611206055" marker-end="url(#arrowhead31941)" style="fill:none"></path><defs><marker id="arrowhead31941" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M107.90625,510.98554611206055L135.8828125,510.98554611206055L173.109375,510.98554611206055" marker-end="url(#arrowhead31942)" style="fill:none"></path><defs><marker id="arrowhead31942" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M90.30850888395992,546.1604084088021L135.8828125,606.9855461120605L163.859375,606.9855461120605" marker-end="url(#arrowhead31943)" style="fill:none"></path><defs><marker id="arrowhead31943" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M79.37288197120047,552.145092905177L135.8828125,702.9855461120605L186.859375,702.9855461120605" marker-end="url(#arrowhead31944)" style="fill:none"></path><defs><marker id="arrowhead31944" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M74.60352482340912,553.6287891977729L135.8828125,798.9855461120605L185.5546875,798.9855461120605" marker-end="url(#arrowhead31945)" style="fill:none"></path><defs><marker id="arrowhead31945" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M72.04554007384345,554.1872823681216L135.8828125,894.9855461120605L181.9375,894.9855461120605" marker-end="url(#arrowhead31946)" style="fill:none"></path><defs><marker id="arrowhead31946" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g></g><g class="edgeLabels"><g class="edgeLabel" transform="translate(135.8828125,126.98554611206055)" style="opacity: 1;"><g transform="translate(-2.9765625,-13)" class="label"><foreignObject width="5.953125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">-</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(312.3671875,43)" style="opacity: 1;"><g transform="translate(-2.9765625,-13)" class="label"><foreignObject width="5.953125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">-</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(312.3671875,210.9710922241211)" style="opacity: 1;"><g transform="translate(-2.9765625,-13)" class="label"><foreignObject width="5.953125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">-</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(135.8828125,222.98554611206055)" style="opacity: 1;"><g transform="translate(-2.9765625,-13)" class="label"><foreignObject width="5.953125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">-</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(135.8828125,318.98554611206055)" style="opacity: 1;"><g transform="translate(-2.9765625,-13)" class="label"><foreignObject width="5.953125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">-</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(135.8828125,414.98554611206055)" style="opacity: 1;"><g transform="translate(-2.9765625,-13)" class="label"><foreignObject width="5.953125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">-</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(135.8828125,510.98554611206055)" style="opacity: 1;"><g transform="translate(-2.9765625,-13)" class="label"><foreignObject width="5.953125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">-</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(135.8828125,606.9855461120605)" style="opacity: 1;"><g transform="translate(-2.9765625,-13)" class="label"><foreignObject width="5.953125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">-</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(135.8828125,702.9855461120605)" style="opacity: 1;"><g transform="translate(-2.9765625,-13)" class="label"><foreignObject width="5.953125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">-</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(135.8828125,798.9855461120605)" style="opacity: 1;"><g transform="translate(-2.9765625,-13)" class="label"><foreignObject width="5.953125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">-</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(135.8828125,894.9855461120605)" style="opacity: 1;"><g transform="translate(-2.9765625,-13)" class="label"><foreignObject width="5.953125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">-</span></div></foreignObject></g></g></g><g class="nodes"><g class="node" id="A" transform="translate(63.953125,510.98554611206055)" style="opacity: 1;"><circle x="-43.953125" y="-23" r="43.953125"></circle><g class="label" transform="translate(0,0)"><g transform="translate(-33.953125,-13)"><foreignObject width="67.90625" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">example1</div></foreignObject></g></g></g><g class="node" id="B" transform="translate(224.125,126.98554611206055)" style="opacity: 1;"><rect rx="5" ry="5" x="-46.78125" y="-23" width="93.5625" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-36.78125,-13)"><foreignObject width="73.5625" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">migrarions</div></foreignObject></g></g></g><g class="node" id="C" transform="translate(435.3148422241211,43)" style="opacity: 1;"><rect rx="0" ry="0" x="-46.2578125" y="-23" width="92.515625" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-36.2578125,-13)"><foreignObject width="72.515625" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">__init__.py</div></foreignObject></g></g></g><g class="node" id="D" transform="translate(435.3148422241211,210.9710922241211)" style="opacity: 1;"><polygon points="94.97109375000001,0 189.94218750000002,-94.97109375000001 94.97109375000001,-189.94218750000002 0,-94.97109375000001" rx="5" ry="5" transform="translate(-94.97109375000001,94.97109375000001)"></polygon><g class="label" transform="translate(0,0)"><g transform="translate(-72.5234375,-13)"><foreignObject width="145.046875" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">Other migration files</div></foreignObject></g></g></g><g class="node" id="E" transform="translate(224.125,222.98554611206055)" style="opacity: 1;"><rect rx="5" ry="5" x="-46.2578125" y="-23" width="92.515625" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-36.2578125,-13)"><foreignObject width="72.515625" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">__init__.py</div></foreignObject></g></g></g><g class="node" id="F" transform="translate(224.125,318.98554611206055)" style="opacity: 1;"><rect rx="5" ry="5" x="-47.265625" y="-23" width="94.53125" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-37.265625,-13)"><foreignObject width="74.53125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">admin.py *</div></foreignObject></g></g></g><g class="node" id="L" transform="translate(224.125,414.98554611206055)" style="opacity: 1;"><rect rx="5" ry="5" x="-36.8046875" y="-23" width="73.609375" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-26.8046875,-13)"><foreignObject width="53.609375" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">apps.py</div></foreignObject></g></g></g><g class="node" id="G" transform="translate(224.125,510.98554611206055)" style="opacity: 1;"><rect rx="5" ry="5" x="-51.015625" y="-23" width="102.03125" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-41.015625,-13)"><foreignObject width="82.03125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">models.py *</div></foreignObject></g></g></g><g class="node" id="I" transform="translate(224.125,606.9855461120605)" style="opacity: 1;"><rect rx="5" ry="5" x="-60.265625" y="-23" width="120.53125" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-50.265625,-13)"><foreignObject width="100.53125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">serializers.py *</div></foreignObject></g></g></g><g class="node" id="K" transform="translate(224.125,702.9855461120605)" style="opacity: 1;"><rect rx="5" ry="5" x="-37.265625" y="-23" width="74.53125" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-27.265625,-13)"><foreignObject width="54.53125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">tests.py</div></foreignObject></g></g></g><g class="node" id="J" transform="translate(224.125,798.9855461120605)" style="opacity: 1;"><rect rx="5" ry="5" x="-38.5703125" y="-23" width="77.140625" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-28.5703125,-13)"><foreignObject width="57.140625" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">urls.py *</div></foreignObject></g></g></g><g class="node" id="H" transform="translate(224.125,894.9855461120605)" style="opacity: 1;"><rect rx="5" ry="5" x="-42.1875" y="-23" width="84.375" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-32.1875,-13)"><foreignObject width="64.375" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">view.py *</div></foreignObject></g></g></g></g></g></g></svg></div>
<p>Note:</p>
<ol>
<li>The file structure of the application should like this figure. And please remeber those files are vital for the application, and do not delete them casually, except migration files. And I will explain why migration files can be deleted at later content.</li>
<li>There are five files with STAR notation need us to work on. Let’s get into there one by one.</li>
</ol>
<h2 id="models.py"><a href="http://Models.py">Models.py</a></h2>
<p>We can create our models at <a href="http://models.py">models.py</a>. There can be more than one model in the <a href="http://models.py">models.py</a>, which means there can be more than one model in an application.</p>
<p>Basically, Django database is based on ORM, this is to say, your database structure is determined by your code in <a href="http://model.py">model.py</a>.</p>
<p>Let’s bulid our model.<br>
<a href="https://github.com/LooDaHu/djangorestframework_example/blob/master/example1/models.py">Click here to MODEL.PY</a></p>
<p>After we finish our code, then we do</p>
<blockquote>
<p>python3 <a href="http://manage.py">manage.py</a> makemigrations</p>
</blockquote>
<p>As you can see, there are two new files, 0001_initial.py and db.sqlite3.<br>
<img src="https://lh3.googleusercontent.com/lIksGDKRFNH-jMQKk02O0J87uAGkRs1XEBNReSGvu6fr2-7cU1WZE1D7coSVRUQvcc6evV9MEK8" alt="enter image description here"></p>
<ul>
<li>
<p>You can regard 0001_initial.py as the blueprint of the database.</p>
</li>
<li>
<p>db.sqlite3 is the brand new database created by the blueprint.</p>
</li>
<li>
<p>We use SQLite3 as our database by default. Of course, you can use<br>
other database you want, and your database setting is at <em>< root_dir>/ main_application/setting.py</em> .</p>
<pre><code>DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
</code></pre>
</li>
</ul>
<p>But we haven’t done yet. Let’s do</p>
<blockquote>
<p>python3 <a href="http://manage.py">manage.py</a> migrate</p>
</blockquote>
<p><img src="https://lh3.googleusercontent.com/srsTro62EmaJIp_5lbypVXpdrGXBVOY8atZSbOSR--7PpPekXmRQ7Vj9Pd1GYt8_18DC3NnG6Q4" alt="enter image description here"></p>
<p>After you see a series of OK, our model and database part is done.</p>
<p>Note: If you have a drastic change on your model and you meet a weired and tough bug when you try modify your database by using <strong>migrate</strong>, I do recommand you delete all migration files and db.sqlite3 which is database. And try it again.</p>
<h2 id="serializers.py"><a href="http://Serializers.py">Serializers.py</a></h2>
<p>Now we need a tool that can transform our data between model and JSON format.<br>
Django REST Framework provides serializers to do this job. What we need to do is extend the built-in serializer to fit our requirement.</p>
<blockquote>
<p>Serializers allow complex data such as querysets and model instances<br>
to be converted to native Python datatypes that can then be easily<br>
rendered into <code>JSON</code>, <code>XML</code> or other content types. Serializers<br>
also provide deserialization, allowing parsed data to be converted<br>
back into complex types, after first validating the incoming data.</p>
<p>The serializers in REST framework work very similarly to Django’s<br>
<code>Form</code> and <code>ModelForm</code> classes. We provide a <code>Serializer</code>class<br>
which gives you a powerful, generic way to control the output of your<br>
responses, as well as a <code>ModelSerializer</code> class which provides a<br>
useful shortcut for creating serializers that deal with model<br>
instances and querysets.</p>
<p>From Django REST Framework</p>
</blockquote>
<p>Let’s start with our code.</p>
<p><a href="https://github.com/LooDaHu/djangorestframework_example/blob/master/example1/serializers.py">Click here to SERIALIZERS.PY</a></p>
<h2 id="views.py"><a href="http://views.py">views.py</a></h2>
<p>Now, we are doing the core of an application. <a href="http://views.py">views.py</a> determines how you RESTful server response the request.</p>
<p>There are different ways to write the code of this part, from low customized to highly customized. Here, I just provide a way which I think should be easy and clear.</p>
<p><a href="https://github.com/LooDaHu/djangorestframework_example/blob/master/example1/views.py">Click here to VIEWS.PY</a></p>
<h2 id="urls.py"><a href="http://urls.py">urls.py</a></h2>
<p>Though we have done the core part of our application, but there is still no route to access our server. So, we have to set urls for our server.</p>
<p>REMEMBER: Do not forget add the urls of the application into the main application, which should be djangorest_example in this case.</p>
<p>< root_dir >/ djangorest_example/ <a href="http://urls.py">urls.py</a></p>
<pre><code>from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('example1.urls')),
]
</code></pre>
<p><a href="https://github.com/LooDaHu/djangorestframework_example/blob/master/example1/urls.py">Click here to URLS.PY</a></p>
<h2 id="admin.py"><a href="http://admin.py">admin.py</a></h2>
<p>We alomost done. But we want our admin site knows we have a new application. So, we need a register in <a href="http://admin.py">admin.py</a>.</p>
<p><a href="https://github.com/LooDaHu/djangorestframework_example/blob/master/example1/admin.py">Click here to ADMIN.PY</a></p>
<h2 id="test">Test</h2>
<ol>
<li>
<p>Let’s try create a new Model1 object by using <a href="https://www.getpostman.com/">POSTMAN</a></p>
</li>
<li>
<p>Oops, someting is wrong here, it shows model2_id : object does not exist, which means our Model1Serializer works well at this point. Due to model2 _id is a foreign key of model1 and related to table Model2.<br>
<img src="https://lh3.googleusercontent.com/L6j0qq2pbNddCVhezB7x2lAUAtw-x91rZVeNAxpVcF3yL61yC7f3QZ4kIupze3QNqI_GcGoD1uc" alt="enter image description here"></p>
</li>
<li>
<p>Let’s create a new Model2 object by admin site. And try it again.<br>
<img src="https://lh3.googleusercontent.com/QLGA7_LmeEvw9uFEVNF_bcGuVM3ITVd2wNjXiVAdB3QFdchWlPdRq9bpYck3Wwh1LayhGq1ThLA" alt="enter image description here"></p>
</li>
<li>
<p>It seems works well. Let’s double check it by GET. It returns expected result.<br>
<img src="https://lh3.googleusercontent.com/uawP4QPa_gcs7bPtk-pkpRBla_lptdI6LRxtidUmIEVZYk-yKkLe3_fpzMYld1VjWgsg9Vp62HQ" alt="enter image description here"></p>
</li>
</ol>
<h2 id="summary">Summary</h2>
<ul>
<li>Here are processing figure to show how it works.</li>
</ul>
<p>GET</p>
<div class="mermaid"><svg xmlns="http://www.w3.org/2000/svg" id="mermaid-svg-CgL7GxExRmm9GW3H" width="100%" style="max-width: 1144.796875px;" viewBox="0 0 1144.796875 206"><g transform="translate(-12, -12)"><g class="output"><g class="clusters"></g><g class="edgePaths"><g class="edgePath" style="opacity: 1;"><path class="path" d="M92.9375,139L119.828125,139L146.71875,139" marker-end="url(#arrowhead31987)" style="fill:none"></path><defs><marker id="arrowhead31987" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M212.953125,139L308.9765625,139L405,139" marker-end="url(#arrowhead31988)" style="fill:none"></path><defs><marker id="arrowhead31988" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M461.4519856770833,116L512.578125,43L539.46875,43" marker-end="url(#arrowhead31989)" style="fill:none"></path><defs><marker id="arrowhead31989" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M630.609375,43L728.8984375,43L827.1875,43" marker-end="url(#arrowhead31990)" style="fill:none"></path><defs><marker id="arrowhead31990" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M913.078125,43L976.125,43L1058.7796266233765,97" marker-end="url(#arrowhead31991)" style="fill:none"></path><defs><marker id="arrowhead31991" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M1058.7796266233765,143L976.125,197L870.1328125,197L728.8984375,197L585.0390625,197L512.578125,197L472.0056573275862,162" marker-end="url(#arrowhead31992)" style="fill:none"></path><defs><marker id="arrowhead31992" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M485.6875,139L512.578125,139L543.4296875,139" marker-end="url(#arrowhead31993)" style="fill:none"></path><defs><marker id="arrowhead31993" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g></g><g class="edgeLabels"><g class="edgeLabel" transform="translate(119.828125,139)" style="opacity: 1;"><g transform="translate(-1.890625,-13)" class="label"><foreignObject width="3.78125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">.</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(308.9765625,139)" style="opacity: 1;"><g transform="translate(-71.0234375,-13)" class="label"><foreignObject width="142.046875" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">route to the method</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(512.578125,43)" style="opacity: 1;"><g transform="translate(-1.890625,-13)" class="label"><foreignObject width="3.78125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">.</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(728.8984375,43)" style="opacity: 1;"><g transform="translate(-51.0234375,-13)" class="label"><foreignObject width="102.046875" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">find the ojbect</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(976.125,43)" style="opacity: 1;"><g transform="translate(-38.046875,-13)" class="label"><foreignObject width="76.09375" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">result back</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(728.8984375,197)" style="opacity: 1;"><g transform="translate(-73.2890625,-13)" class="label"><foreignObject width="146.578125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">serialized data/JSON</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(512.578125,139)" style="opacity: 1;"><g transform="translate(-1.890625,-13)" class="label"><foreignObject width="3.78125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">.</span></div></foreignObject></g></g></g><g class="nodes"><g class="node" id="request" transform="translate(56.46875,139)" style="opacity: 1;"><rect rx="0" ry="0" x="-36.46875" y="-23" width="72.9375" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-26.46875,-13)"><foreignObject width="52.9375" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">request</div></foreignObject></g></g></g><g class="node" id="urls.py" transform="translate(179.8359375,139)" style="opacity: 1;"><rect rx="0" ry="0" x="-33.1171875" y="-23" width="66.234375" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-23.1171875,-13)"><foreignObject width="46.234375" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">urls.py</div></foreignObject></g></g></g><g class="node" id="views.py" transform="translate(445.34375,139)" style="opacity: 1;"><rect rx="0" ry="0" x="-40.34375" y="-23" width="80.6875" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-30.34375,-13)"><foreignObject width="60.6875" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">views.py</div></foreignObject></g></g></g><g class="node" id="models.py" transform="translate(585.0390625,43)" style="opacity: 1;"><rect rx="0" ry="0" x="-45.5703125" y="-23" width="91.140625" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-35.5703125,-13)"><foreignObject width="71.140625" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">models.py</div></foreignObject></g></g></g><g class="node" id="Database" transform="translate(870.1328125,43)" style="opacity: 1;"><rect rx="0" ry="0" x="-42.9453125" y="-23" width="85.890625" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-32.9453125,-13)"><foreignObject width="65.890625" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">Database</div></foreignObject></g></g></g><g class="node" id="serializers.py" transform="translate(1093.984375,120)" style="opacity: 1;"><rect rx="0" ry="0" x="-54.8125" y="-23" width="109.625" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-44.8125,-13)"><foreignObject width="89.625" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">serializers.py</div></foreignObject></g></g></g><g class="node" id="response" transform="translate(585.0390625,139)" style="opacity: 1;"><rect rx="0" ry="0" x="-41.609375" y="-23" width="83.21875" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-31.609375,-13)"><foreignObject width="63.21875" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">response</div></foreignObject></g></g></g></g></g></g></svg></div>
<p>POST/ PUT/ PATCH</p>
<div class="mermaid"><svg xmlns="http://www.w3.org/2000/svg" id="mermaid-svg-q1W3WioQZJrCConu" width="100%" style="max-width: 1280.96875px;" viewBox="0 0 1280.96875 206"><g transform="translate(-12, -12)"><g class="output"><g class="clusters"></g><g class="edgePaths"><g class="edgePath" style="opacity: 1;"><path class="path" d="M92.9375,139L119.828125,139L146.71875,139" marker-end="url(#arrowhead32034)" style="fill:none"></path><defs><marker id="arrowhead32034" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M212.953125,139L308.9765625,139L405,139" marker-end="url(#arrowhead32035)" style="fill:none"></path><defs><marker id="arrowhead32035" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M461.4519856770833,116L512.578125,43L539.46875,43" marker-end="url(#arrowhead32036)" style="fill:none"></path><defs><marker id="arrowhead32036" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M649.09375,43L766.2890625,43L883.484375,43" marker-end="url(#arrowhead32037)" style="fill:none"></path><defs><marker id="arrowhead32037" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M974.625,43L1086.8515625,43L1199.078125,98.68950760245696" marker-end="url(#arrowhead32038)" style="fill:none"></path><defs><marker id="arrowhead32038" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M1199.078125,141.31049239754304L1086.8515625,197L929.0546875,197L766.2890625,197L594.28125,197L512.578125,197L472.0056573275862,162" marker-end="url(#arrowhead32039)" style="fill:none"></path><defs><marker id="arrowhead32039" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M485.6875,139L512.578125,139L552.671875,139" marker-end="url(#arrowhead32040)" style="fill:none"></path><defs><marker id="arrowhead32040" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g></g><g class="edgeLabels"><g class="edgeLabel" transform="translate(119.828125,139)" style="opacity: 1;"><g transform="translate(-1.890625,-13)" class="label"><foreignObject width="3.78125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">.</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(308.9765625,139)" style="opacity: 1;"><g transform="translate(-71.0234375,-13)" class="label"><foreignObject width="142.046875" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">route to the method</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(512.578125,43)" style="opacity: 1;"><g transform="translate(-1.890625,-13)" class="label"><foreignObject width="3.78125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">.</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(766.2890625,43)" style="opacity: 1;"><g transform="translate(-85.7890625,-13)" class="label"><foreignObject width="171.578125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">deserialized data/Object</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(1086.8515625,43)" style="opacity: 1;"><g transform="translate(-87.2265625,-13)" class="label"><foreignObject width="174.453125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">create/update the ojbect</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(766.2890625,197)" style="opacity: 1;"><g transform="translate(-92.1953125,-13)" class="label"><foreignObject width="184.390625" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">result back success/failure</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(512.578125,139)" style="opacity: 1;"><g transform="translate(-1.890625,-13)" class="label"><foreignObject width="3.78125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">.</span></div></foreignObject></g></g></g><g class="nodes"><g class="node" id="request" transform="translate(56.46875,139)" style="opacity: 1;"><rect rx="0" ry="0" x="-36.46875" y="-23" width="72.9375" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-26.46875,-13)"><foreignObject width="52.9375" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">request</div></foreignObject></g></g></g><g class="node" id="urls.py" transform="translate(179.8359375,139)" style="opacity: 1;"><rect rx="0" ry="0" x="-33.1171875" y="-23" width="66.234375" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-23.1171875,-13)"><foreignObject width="46.234375" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">urls.py</div></foreignObject></g></g></g><g class="node" id="views.py" transform="translate(445.34375,139)" style="opacity: 1;"><rect rx="0" ry="0" x="-40.34375" y="-23" width="80.6875" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-30.34375,-13)"><foreignObject width="60.6875" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">views.py</div></foreignObject></g></g></g><g class="node" id="serializers.py" transform="translate(594.28125,43)" style="opacity: 1;"><rect rx="0" ry="0" x="-54.8125" y="-23" width="109.625" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-44.8125,-13)"><foreignObject width="89.625" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">serializers.py</div></foreignObject></g></g></g><g class="node" id="models.py" transform="translate(929.0546875,43)" style="opacity: 1;"><rect rx="0" ry="0" x="-45.5703125" y="-23" width="91.140625" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-35.5703125,-13)"><foreignObject width="71.140625" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">models.py</div></foreignObject></g></g></g><g class="node" id="Database" transform="translate(1242.0234375,120)" style="opacity: 1;"><rect rx="0" ry="0" x="-42.9453125" y="-23" width="85.890625" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-32.9453125,-13)"><foreignObject width="65.890625" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">Database</div></foreignObject></g></g></g><g class="node" id="response" transform="translate(594.28125,139)" style="opacity: 1;"><rect rx="0" ry="0" x="-41.609375" y="-23" width="83.21875" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-31.609375,-13)"><foreignObject width="63.21875" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">response</div></foreignObject></g></g></g></g></g></g></svg></div>
<p>DELETE</p>
<div class="mermaid"><svg xmlns="http://www.w3.org/2000/svg" id="mermaid-svg-zFEr189yJlGusFHY" width="100%" style="max-width: 957.796875px;" viewBox="0 0 957.796875 219"><g transform="translate(-12, -12)"><g class="output"><g class="clusters"></g><g class="edgePaths"><g class="edgePath" style="opacity: 1;"><path class="path" d="M92.9375,139L119.828125,139L146.71875,139" marker-end="url(#arrowhead32073)" style="fill:none"></path><defs><marker id="arrowhead32073" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M212.953125,139L308.9765625,139L405,139" marker-end="url(#arrowhead32074)" style="fill:none"></path><defs><marker id="arrowhead32074" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M461.4519856770833,116L512.578125,43L586.09375,43" marker-end="url(#arrowhead32075)" style="fill:none"></path><defs><marker id="arrowhead32075" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M677.234375,43L799.8828125,43L886.0817271706587,103.5" marker-end="url(#arrowhead32076)" style="fill:none"></path><defs><marker id="arrowhead32076" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M886.0817271706587,149.5L799.8828125,210L631.6640625,210L512.578125,210L467.1238996478873,162" marker-end="url(#arrowhead32077)" style="fill:none"></path><defs><marker id="arrowhead32077" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g><g class="edgePath" style="opacity: 1;"><path class="path" d="M485.6875,139L512.578125,139L590.0546875,139" marker-end="url(#arrowhead32078)" style="fill:none"></path><defs><marker id="arrowhead32078" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowheadPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"></path></marker></defs></g></g><g class="edgeLabels"><g class="edgeLabel" transform="translate(119.828125,139)" style="opacity: 1;"><g transform="translate(-1.890625,-13)" class="label"><foreignObject width="3.78125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">.</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(308.9765625,139)" style="opacity: 1;"><g transform="translate(-71.0234375,-13)" class="label"><foreignObject width="142.046875" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">route to the method</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(512.578125,43)" style="opacity: 1;"><g transform="translate(-1.890625,-13)" class="label"><foreignObject width="3.78125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">.</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(799.8828125,43)" style="opacity: 1;"><g transform="translate(-51.0234375,-13)" class="label"><foreignObject width="102.046875" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">find the ojbect</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(631.6640625,210)" style="opacity: 1;"><g transform="translate(-92.1953125,-13)" class="label"><foreignObject width="184.390625" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">result back success/failure</span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(512.578125,139)" style="opacity: 1;"><g transform="translate(-1.890625,-13)" class="label"><foreignObject width="3.78125" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;"><span class="edgeLabel">.</span></div></foreignObject></g></g></g><g class="nodes"><g class="node" id="request" transform="translate(56.46875,139)" style="opacity: 1;"><rect rx="0" ry="0" x="-36.46875" y="-23" width="72.9375" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-26.46875,-13)"><foreignObject width="52.9375" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">request</div></foreignObject></g></g></g><g class="node" id="urls.py" transform="translate(179.8359375,139)" style="opacity: 1;"><rect rx="0" ry="0" x="-33.1171875" y="-23" width="66.234375" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-23.1171875,-13)"><foreignObject width="46.234375" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">urls.py</div></foreignObject></g></g></g><g class="node" id="views.py" transform="translate(445.34375,139)" style="opacity: 1;"><rect rx="0" ry="0" x="-40.34375" y="-23" width="80.6875" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-30.34375,-13)"><foreignObject width="60.6875" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">views.py</div></foreignObject></g></g></g><g class="node" id="models.py" transform="translate(631.6640625,43)" style="opacity: 1;"><rect rx="0" ry="0" x="-45.5703125" y="-23" width="91.140625" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-35.5703125,-13)"><foreignObject width="71.140625" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">models.py</div></foreignObject></g></g></g><g class="node" id="Database" transform="translate(918.8515625,126.5)" style="opacity: 1;"><rect rx="0" ry="0" x="-42.9453125" y="-23" width="85.890625" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-32.9453125,-13)"><foreignObject width="65.890625" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">Database</div></foreignObject></g></g></g><g class="node" id="response" transform="translate(631.6640625,139)" style="opacity: 1;"><rect rx="0" ry="0" x="-41.609375" y="-23" width="83.21875" height="46"></rect><g class="label" transform="translate(0,0)"><g transform="translate(-31.609375,-13)"><foreignObject width="63.21875" height="26"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; white-space: nowrap;">response</div></foreignObject></g></g></g></g></g></g></svg></div>
<ul>
<li>
<p>Build proper model is the first key step to create a good<br>
application.</p>
</li>
<li>
<p>Be care of your every step, small problem, like a typo, could take<br>
much time.</p>
</li>
</ul>
<h1 id="retrofit2">Retrofit2</h1>
<p>To be done</p>
<h1 id="contact">Contact</h1>
<p>If you have any question about the above content, be free to contact me.</p>
<blockquote>
<p>Developer: Jinming Yang<br>
Email: <a href="mailto:jy345@nau.edu">jy345@nau.edu</a><br>
Github: @LooDaHu<br>
WeChat: a651120561</p>
</blockquote>
<p>This is just a simple tutorial how to fast set up, if you want to learn more and deep, please refer <a href="https://www.django-rest-framework.org/">API GUIDE</a></p>
<p>Because Django_REST_framework is based on Django, if you feel not good enough for Django_REST_framework, using <a href="https://docs.djangoproject.com/en/2.2/">Django</a> is a good option to develop your code.</p>
</div>
</div>
</body>
</html>