mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-16 19:22:24 +03:00
fix: changing default project name to my_project
This commit is contained in:
parent
73cbb9cd4a
commit
c078b336b2
|
@ -18,32 +18,32 @@ Create a new Django project named `tutorial`, then start a new app called `quick
|
||||||
pip install djangorestframework
|
pip install djangorestframework
|
||||||
|
|
||||||
# Set up a new project with a single application
|
# Set up a new project with a single application
|
||||||
django-admin startproject tutorial . # Note the trailing '.' character
|
django-admin startproject my_project . # Note the trailing '.' character
|
||||||
cd tutorial
|
cd my_project
|
||||||
django-admin startapp quickstart
|
django-admin startapp quickstart
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
The project layout should look like:
|
The project layout should look like:
|
||||||
|
|
||||||
$ pwd
|
$ pwd
|
||||||
<some path>/tutorial
|
<some path>/my_project
|
||||||
$ find .
|
$ find .
|
||||||
.
|
.
|
||||||
./tutorial
|
./my_project
|
||||||
./tutorial/asgi.py
|
./my_project/asgi.py
|
||||||
./tutorial/__init__.py
|
./my_project/__init__.py
|
||||||
./tutorial/quickstart
|
./my_project/quickstart
|
||||||
./tutorial/quickstart/migrations
|
./my_project/quickstart/migrations
|
||||||
./tutorial/quickstart/migrations/__init__.py
|
./my_project/quickstart/migrations/__init__.py
|
||||||
./tutorial/quickstart/models.py
|
./my_project/quickstart/models.py
|
||||||
./tutorial/quickstart/__init__.py
|
./my_project/quickstart/__init__.py
|
||||||
./tutorial/quickstart/apps.py
|
./my_project/quickstart/apps.py
|
||||||
./tutorial/quickstart/admin.py
|
./my_project/quickstart/admin.py
|
||||||
./tutorial/quickstart/tests.py
|
./my_project/quickstart/tests.py
|
||||||
./tutorial/quickstart/views.py
|
./my_project/quickstart/views.py
|
||||||
./tutorial/settings.py
|
./my_project/settings.py
|
||||||
./tutorial/urls.py
|
./my_project/urls.py
|
||||||
./tutorial/wsgi.py
|
./my_project/wsgi.py
|
||||||
./env
|
./env
|
||||||
./env/...
|
./env/...
|
||||||
./manage.py
|
./manage.py
|
||||||
|
@ -62,7 +62,7 @@ Once you've set up a database and the initial user is created and ready to go, o
|
||||||
|
|
||||||
## Serializers
|
## Serializers
|
||||||
|
|
||||||
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.
|
First up we're going to define some serializers. Let's create a new module named `my_project/quickstart/serializers.py` that we'll use for our data representations.
|
||||||
|
|
||||||
from django.contrib.auth.models import Group, User
|
from django.contrib.auth.models import Group, User
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
@ -83,12 +83,12 @@ Notice that we're using hyperlinked relations in this case with `HyperlinkedMode
|
||||||
|
|
||||||
## Views
|
## Views
|
||||||
|
|
||||||
Right, we'd better write some views then. Open `tutorial/quickstart/views.py` and get typing.
|
Right, we'd better write some views then. Open `my_project/quickstart/views.py` and get typing.
|
||||||
|
|
||||||
from django.contrib.auth.models import Group, User
|
from django.contrib.auth.models import Group, User
|
||||||
from rest_framework import permissions, viewsets
|
from rest_framework import permissions, viewsets
|
||||||
|
|
||||||
from tutorial.quickstart.serializers import GroupSerializer, UserSerializer
|
from my_project.quickstart.serializers import GroupSerializer, UserSerializer
|
||||||
|
|
||||||
|
|
||||||
class UserViewSet(viewsets.ModelViewSet):
|
class UserViewSet(viewsets.ModelViewSet):
|
||||||
|
@ -114,12 +114,12 @@ We can easily break these down into individual views if we need to, but using vi
|
||||||
|
|
||||||
## URLs
|
## URLs
|
||||||
|
|
||||||
Okay, now let's wire up the API URLs. On to `tutorial/urls.py`...
|
Okay, now let's wire up the API URLs. On to `my_project/urls.py`...
|
||||||
|
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
|
|
||||||
from tutorial.quickstart import views
|
from my_project.quickstart import views
|
||||||
|
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
router.register(r'users', views.UserViewSet)
|
router.register(r'users', views.UserViewSet)
|
||||||
|
@ -139,7 +139,7 @@ Again, if we need more control over the API URLs we can simply drop down to usin
|
||||||
Finally, we're including default login and logout views for use with the browsable API. That's optional, but useful if your API requires authentication and you want to use the browsable API.
|
Finally, we're including default login and logout views for use with the browsable API. That's optional, but useful if your API requires authentication and you want to use the browsable API.
|
||||||
|
|
||||||
## Pagination
|
## Pagination
|
||||||
Pagination allows you to control how many objects per page are returned. To enable it add the following lines to `tutorial/settings.py`
|
Pagination allows you to control how many objects per page are returned. To enable it add the following lines to `my_project/settings.py`
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
||||||
|
@ -148,7 +148,7 @@ Pagination allows you to control how many objects per page are returned. To enab
|
||||||
|
|
||||||
## Settings
|
## Settings
|
||||||
|
|
||||||
Add `'rest_framework'` to `INSTALLED_APPS`. The settings module will be in `tutorial/settings.py`
|
Add `'rest_framework'` to `INSTALLED_APPS`. The settings module will be in `my_project/settings.py`
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
...
|
...
|
||||||
|
|
Loading…
Reference in New Issue
Block a user