You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorial/quickstart.md
+29-25
Original file line number
Diff line number
Diff line change
@@ -30,40 +30,42 @@ The project layout should look like:
30
30
<some path>/tutorial
31
31
$ find .
32
32
.
33
-
./manage.py
34
33
./tutorial
34
+
./tutorial/asgi.py
35
35
./tutorial/__init__.py
36
36
./tutorial/quickstart
37
-
./tutorial/quickstart/__init__.py
38
-
./tutorial/quickstart/admin.py
39
-
./tutorial/quickstart/apps.py
40
37
./tutorial/quickstart/migrations
41
38
./tutorial/quickstart/migrations/__init__.py
42
39
./tutorial/quickstart/models.py
40
+
./tutorial/quickstart/__init__.py
41
+
./tutorial/quickstart/apps.py
42
+
./tutorial/quickstart/admin.py
43
43
./tutorial/quickstart/tests.py
44
44
./tutorial/quickstart/views.py
45
-
./tutorial/asgi.py
46
45
./tutorial/settings.py
47
46
./tutorial/urls.py
48
47
./tutorial/wsgi.py
48
+
./env
49
+
./env/...
50
+
./manage.py
49
51
50
52
It may look unusual that the application has been created within the project directory. Using the project's namespace avoids name clashes with external modules (a topic that goes outside the scope of the quickstart).
51
53
52
54
Now sync your database for the first time:
53
55
54
56
python manage.py migrate
55
57
56
-
We'll also create an initial user named `admin` with a password of `password123`. We'll authenticate as that user later in our example.
58
+
We'll also create an initial user named `admin` with a password. We'll authenticate as that user later in our example.
Once you've set up a database and the initial user is created and ready to go, open up the app's directory and we'll get coding...
61
63
62
64
## Serializers
63
65
64
66
First up we're going to define some serializers. Let's create a new module named `tutorial/quickstart/serializers.py` that we'll use for our data representations.
65
67
66
-
from django.contrib.auth.models import User, Group
68
+
from django.contrib.auth.models import Group, User
67
69
from rest_framework import serializers
68
70
69
71
@@ -84,10 +86,10 @@ Notice that we're using hyperlinked relations in this case with `HyperlinkedMode
84
86
85
87
Right, we'd better write some views then. Open `tutorial/quickstart/views.py` and get typing.
86
88
87
-
from django.contrib.auth.models import User, Group
88
-
from rest_framework import viewsets
89
-
from rest_framework import permissions
90
-
from tutorial.quickstart.serializers import UserSerializer, GroupSerializer
89
+
from django.contrib.auth.models import Group, User
90
+
from rest_framework import permissions, viewsets
91
+
92
+
from tutorial.quickstart.serializers import GroupSerializer, UserSerializer
91
93
92
94
93
95
class UserViewSet(viewsets.ModelViewSet):
@@ -117,6 +119,7 @@ Okay, now let's wire up the API URLs. On to `tutorial/urls.py`...
117
119
118
120
from django.urls import include, path
119
121
from rest_framework import routers
122
+
120
123
from tutorial.quickstart import views
121
124
122
125
router = routers.DefaultRouter()
@@ -165,38 +168,39 @@ We're now ready to test the API we've built. Let's fire up the server from the
165
168
166
169
We can now access our API, both from the command-line, using tools like `curl`...
0 commit comments