Skip to content

Commit 2510456

Browse files
authored
Update quickstart.md (#8575)
* Update quickstart.md * Use PEP 8 compliant import * Remove unauthorized password by Django (too common)
1 parent 041b88f commit 2510456

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

docs/tutorial/quickstart.md

+29-25
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,42 @@ The project layout should look like:
3030
<some path>/tutorial
3131
$ find .
3232
.
33-
./manage.py
3433
./tutorial
34+
./tutorial/asgi.py
3535
./tutorial/__init__.py
3636
./tutorial/quickstart
37-
./tutorial/quickstart/__init__.py
38-
./tutorial/quickstart/admin.py
39-
./tutorial/quickstart/apps.py
4037
./tutorial/quickstart/migrations
4138
./tutorial/quickstart/migrations/__init__.py
4239
./tutorial/quickstart/models.py
40+
./tutorial/quickstart/__init__.py
41+
./tutorial/quickstart/apps.py
42+
./tutorial/quickstart/admin.py
4343
./tutorial/quickstart/tests.py
4444
./tutorial/quickstart/views.py
45-
./tutorial/asgi.py
4645
./tutorial/settings.py
4746
./tutorial/urls.py
4847
./tutorial/wsgi.py
48+
./env
49+
./env/...
50+
./manage.py
4951

5052
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).
5153

5254
Now sync your database for the first time:
5355

5456
python manage.py migrate
5557

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.
5759

58-
python manage.py createsuperuser --email admin@example.com --username admin
60+
python manage.py createsuperuser --username admin --email admin@example.com
5961

6062
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...
6163

6264
## Serializers
6365

6466
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.
6567

66-
from django.contrib.auth.models import User, Group
68+
from django.contrib.auth.models import Group, User
6769
from rest_framework import serializers
6870

6971

@@ -84,10 +86,10 @@ Notice that we're using hyperlinked relations in this case with `HyperlinkedMode
8486

8587
Right, we'd better write some views then. Open `tutorial/quickstart/views.py` and get typing.
8688

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
9193

9294

9395
class UserViewSet(viewsets.ModelViewSet):
@@ -117,6 +119,7 @@ Okay, now let's wire up the API URLs. On to `tutorial/urls.py`...
117119

118120
from django.urls import include, path
119121
from rest_framework import routers
122+
120123
from tutorial.quickstart import views
121124

122125
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
165168

166169
We can now access our API, both from the command-line, using tools like `curl`...
167170

168-
bash: curl -H 'Accept: application/json; indent=4' -u admin:password123 http://127.0.0.1:8000/users/
171+
bash: curl -u admin -H 'Accept: application/json; indent=4' http://127.0.0.1:8000/users/
172+
Enter host password for user 'admin':
169173
{
170-
"count": 2,
174+
"count": 1,
171175
"next": null,
172176
"previous": null,
173177
"results": [
174178
{
175-
"email": "[email protected]",
176-
"groups": [],
177179
"url": "http://127.0.0.1:8000/users/1/",
178-
"username": "admin"
179-
},
180+
"username": "admin",
181+
"email": "[email protected]",
182+
"groups": []
183+
}
180184
]
181185
}
182186

183187
Or using the [httpie][httpie], command line tool...
184188

185-
bash: http -a admin:password123 http://127.0.0.1:8000/users/
186-
187-
HTTP/1.1 200 OK
189+
bash: http -a admin http://127.0.0.1:8000/users/
190+
http: password for [email protected]:8000::
191+
$HTTP/1.1 200 OK
188192
...
189193
{
190-
"count": 2,
194+
"count": 1,
191195
"next": null,
192196
"previous": null,
193197
"results": [
194198
{
195199
"email": "[email protected]",
196200
"groups": [],
197-
"url": "http://localhost:8000/users/1/",
198-
"username": "paul"
199-
},
201+
"url": "http://127.0.0.1:8000/users/1/",
202+
"username": "admin"
203+
}
200204
]
201205
}
202206

0 commit comments

Comments
 (0)