Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
f322e894
Commit
f322e894
authored
Nov 18, 2013
by
Omer Katz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enabled syntax highlighting in the README file.
parent
fb3fcf07
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
17 deletions
+20
-17
README.md
+20
-17
No files found.
README.md
View file @
f322e894
...
@@ -48,36 +48,39 @@ Let's take a look at a quick example of using REST framework to build a simple m
...
@@ -48,36 +48,39 @@ Let's take a look at a quick example of using REST framework to build a simple m
Here's our project's root
`urls.py`
module:
Here's our project's root
`urls.py`
module:
from django.conf.urls.defaults import url, patterns, include
```
python
from django.contrib.auth.models import User, Group
from
django.conf.urls.defaults
import
url
,
patterns
,
include
from rest_framework import viewsets, routers
from
django.contrib.auth.models
import
User
,
Group
from
rest_framework
import
viewsets
,
routers
# ViewSets define the view behavior.
# ViewSets define the view behavior.
class UserViewSet(viewsets.ModelViewSet):
class
UserViewSet
(
viewsets
.
ModelViewSet
):
model
=
User
model
=
User
class GroupViewSet(viewsets.ModelViewSet):
class
GroupViewSet
(
viewsets
.
ModelViewSet
):
model
=
Group
model
=
Group
# Routers provide an easy way of automatically determining the URL conf
# Routers provide an easy way of automatically determining the URL conf
router = routers.DefaultRouter()
router
=
routers
.
DefaultRouter
()
router.register(r'users', UserViewSet)
router
.
register
(
r'users'
,
UserViewSet
)
router.register(r'groups', GroupViewSet)
router
.
register
(
r'groups'
,
GroupViewSet
)
# Wire up our API using automatic URL routing.
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browseable API.
# Additionally, we include login URLs for the browseable API.
urlpatterns = patterns('',
urlpatterns
=
patterns
(
''
,
url
(
r'^'
,
include
(
router
.
urls
)),
url
(
r'^'
,
include
(
router
.
urls
)),
url
(
r'^api-auth/'
,
include
(
'rest_framework.urls'
,
namespace
=
'rest_framework'
))
url
(
r'^api-auth/'
,
include
(
'rest_framework.urls'
,
namespace
=
'rest_framework'
))
)
)
```
We'd also like to configure a couple of settings for our API.
We'd also like to configure a couple of settings for our API.
Add the following to your
`settings.py`
module:
Add the following to your
`settings.py`
module:
REST_FRAMEWORK = {
```
python
REST_FRAMEWORK
=
{
# Use hyperlinked styles by default.
# Use hyperlinked styles by default.
# Only used if the `serializer_class` attribute is not set on a view.
# Only used if the `serializer_class` attribute is not set on a view.
'DEFAULT_MODEL_SERIALIZER_CLASS'
:
'DEFAULT_MODEL_SERIALIZER_CLASS'
:
...
@@ -88,8 +91,8 @@ Add the following to your `settings.py` module:
...
@@ -88,8 +91,8 @@ Add the following to your `settings.py` module:
'DEFAULT_PERMISSION_CLASSES'
:
[
'DEFAULT_PERMISSION_CLASSES'
:
[
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
]
]
}
}
```
Don't forget to make sure you've also added
`rest_framework`
to your
`INSTALLED_APPS`
setting.
Don't forget to make sure you've also added
`rest_framework`
to your
`INSTALLED_APPS`
setting.
That's it, we're done!
That's it, we're done!
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment