Django's class based views are a welcome departure from the old-style views.
diff --git a/index.html b/index.html
index 801050ff9..6df00f0ad 100644
--- a/index.html
+++ b/index.html
@@ -140,18 +140,19 @@ cd django-rest-framework
pip install -r requirements.txt
pip install -r optionals.txt
-Add djangorestframework
to your INSTALLED_APPS
.
+Add rest_framework
to your INSTALLED_APPS
.
INSTALLED_APPS = (
...
- 'djangorestframework',
+ 'rest_framework',
)
If you're intending to use the browserable API you'll want to add REST framework's login and logout views. Add the following to your root urls.py
file.
urlpatterns = patterns('',
...
- url(r'^api-auth/', include('djangorestframework.urls', namespace='djangorestframework'))
+ url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
)
+Note that the base URL can be whatever you want, but you must include rest_framework.urls
with the rest_framework
namespace.
Quickstart
TODO
Tutorial
@@ -199,7 +200,7 @@ pip install -r optionals.txt
./mkdocs.py
Run the tests:
-./djangorestframework/runtests/runtests.py
+./rest_framework/runtests/runtests.py
License
Copyright (c) 2011-2012, Tom Christie
diff --git a/topics/browsable-api.html b/topics/browsable-api.html
index d69958b14..93eeebf48 100644
--- a/topics/browsable-api.html
+++ b/topics/browsable-api.html
@@ -106,11 +106,11 @@
Working with the Browsable API
API may stand for Application Programming Interface, but humans have to be able to read the APIs, too; someone has to do the programming. Django REST Framework supports generating human-friendly HTML output for each resource when the HTML
format is requested. These pages allow for easy browsing of resources, as well as forms for submitting data to the resources using POST
, PUT
, and DELETE
.
URLs
-If you include fully-qualified URLs in your resource output, they will be 'urlized' and made clickable for easy browsing by humans. The djangorestframework
package includes a reverse
helper for this purpose.
+If you include fully-qualified URLs in your resource output, they will be 'urlized' and made clickable for easy browsing by humans. The rest_framework
package includes a reverse
helper for this purpose.
By default, the API will return the format specified by the headers, which in the case of the browser is HTML. The format can be specified using ?format=
in the request, so you can look at the raw JSON response in a browser by adding ?format=json
to the URL. There are helpful extensions for viewing JSON in Firefox and Chrome.
Customizing
-To customize the look-and-feel, create a template called api.html
and add it to your project, eg: templates/djangorestframework/api.html
, that extends the djangorestframework/base.html
template.
+To customize the look-and-feel, create a template called api.html
and add it to your project, eg: templates/rest_framework/api.html
, that extends the rest_framework/base.html
template.
The included browsable API template is built with Bootstrap (2.1.1), making it easy to customize the look-and-feel.
Theme
To replace the theme wholesale, add a bootstrap_theme
block to your api.html
and insert a link
to the desired Bootstrap theme css file. This will completely replace the included theme.
diff --git a/topics/credits.html b/topics/credits.html
index 76da1d1e5..c89081c5b 100644
--- a/topics/credits.html
+++ b/topics/credits.html
@@ -143,6 +143,7 @@
Can Yavuz - tschan
Shawn Lewis - shawnlewis
Alec Perkins - alecperkins
+Michael Barrett - phobologic
Many thanks to everyone who's contributed to the project.
Additional thanks
diff --git a/tutorial/1-serialization.html b/tutorial/1-serialization.html
index 01b71c2dd..2ffaf5126 100644
--- a/tutorial/1-serialization.html
+++ b/tutorial/1-serialization.html
@@ -145,10 +145,10 @@ cd tutorial
}
}
-We'll also need to add our new blog
app and the djangorestframework
app to INSTALLED_APPS
.
+We'll also need to add our new blog
app and the rest_framework
app to INSTALLED_APPS
.
INSTALLED_APPS = (
...
- 'djangorestframework',
+ 'rest_framework',
'blog'
)
@@ -173,7 +173,7 @@ class Comment(models.Model):
Creating a Serializer class
We're going to create a simple Web API that we can use to edit these comment objects with. The first thing we need is a way of serializing and deserializing the objects into representations such as json
. We do this by declaring serializers, that work very similarly to Django's forms. Create a file in the project named serializers.py
and add the following.
from blog import models
-from djangorestframework import serializers
+from rest_framework import serializers
class CommentSerializer(serializers.Serializer):
email = serializers.EmailField()
@@ -201,8 +201,8 @@ class CommentSerializer(serializers.Serializer):
Okay, once we've got a few imports out of the way, we'd better create a few comments to work with.
from blog.models import Comment
from blog.serializers import CommentSerializer
-from djangorestframework.renderers import JSONRenderer
-from djangorestframework.parsers import JSONParser
+from rest_framework.renderers import JSONRenderer
+from rest_framework.parsers import JSONParser
c1 = Comment(email='leila@example.com', content='nothing to say')
c2 = Comment(email='tom@example.com', content='foo bar')
@@ -238,8 +238,8 @@ We'll start off by creating a subclass of HttpResponse that we can use to render
Edit the blog/views.py
file, and add the following.
from blog.models import Comment
from blog.serializers import CommentSerializer
-from djangorestframework.renderers import JSONRenderer
-from djangorestframework.parsers import JSONParser
+from rest_framework.renderers import JSONRenderer
+from rest_framework.parsers import JSONParser
from django.http import HttpResponse
class JSONResponse(HttpResponse):
diff --git a/tutorial/2-requests-and-responses.html b/tutorial/2-requests-and-responses.html
index 82011802a..9e0170702 100644
--- a/tutorial/2-requests-and-responses.html
+++ b/tutorial/2-requests-and-responses.html
@@ -135,9 +135,9 @@ request.DATA # Handles arbitrary data. Works any HTTP request with content.
We don't need our JSONResponse
class anymore, so go ahead and delete that. Once that's done we can start refactoring our views slightly.
from blog.models import Comment
from blog.serializers import CommentSerializer
-from djangorestframework import status
-from djangorestframework.decorators import api_view
-from djangorestframework.response import Response
+from rest_framework import status
+from rest_framework.decorators import api_view
+from rest_framework.response import Response
@api_view(['GET', 'POST'])
def comment_root(request):
@@ -198,7 +198,7 @@ def comment_instance(request, pk):
Now update the urls.py
file slightly, to append a set of format_suffix_patterns
in addition to the existing URLs.
from django.conf.urls import patterns, url
-from djangorestframework.urlpatterns import format_suffix_patterns
+from rest_framework.urlpatterns import format_suffix_patterns
urlpatterns = patterns('blogpost.views',
url(r'^$', 'comment_root'),
diff --git a/tutorial/3-class-based-views.html b/tutorial/3-class-based-views.html
index 5621f93f9..89aa03687 100644
--- a/tutorial/3-class-based-views.html
+++ b/tutorial/3-class-based-views.html
@@ -110,9 +110,9 @@
from blog.models import Comment
from blog.serializers import CommentSerializer
from django.http import Http404
-from djangorestframework.views import APIView
-from djangorestframework.response import Response
-from djangorestframework import status
+from rest_framework.views import APIView
+from rest_framework.response import Response
+from rest_framework import status
class CommentRoot(APIView):
"""
@@ -165,7 +165,7 @@ class CommentRoot(APIView):
That's looking good. Again, it's still pretty similar to the function based view right now.
We'll also need to refactor our URLconf slightly now we're using class based views.
from django.conf.urls import patterns, url
-from djangorestframework.urlpatterns import format_suffix_patterns
+from rest_framework.urlpatterns import format_suffix_patterns
from blogpost import views
urlpatterns = patterns('',
@@ -182,8 +182,8 @@ urlpatterns = format_suffix_patterns(urlpatterns)
Let's take a look at how we can compose our views by using the mixin classes.
from blog.models import Comment
from blog.serializers import CommentSerializer
-from djangorestframework import mixins
-from djangorestframework import generics
+from rest_framework import mixins
+from rest_framework import generics
class CommentRoot(mixins.ListModelMixin,
mixins.CreateModelMixin,
@@ -220,7 +220,7 @@ class CommentRoot(mixins.ListModelMixin,
Using the mixin classes we've rewritten the views to use slightly less code than before, but we can go one step further. REST framework provides a set of already mixed-in generic views that we can use.
from blog.models import Comment
from blog.serializers import CommentSerializer
-from djangorestframework import generics
+from rest_framework import generics
class CommentRoot(generics.RootAPIView):
model = Comment
diff --git a/tutorial/6-resource-orientated-projects.html b/tutorial/6-resource-orientated-projects.html
index 29d92f5f8..62ed50f9f 100644
--- a/tutorial/6-resource-orientated-projects.html
+++ b/tutorial/6-resource-orientated-projects.html
@@ -149,7 +149,7 @@ urlpatterns = patterns('blogpost.views',
Using Routers
Right now that hasn't really saved us a lot of code. However, now that we're using Resources rather than Views, we actually don't need to design the urlconf ourselves. The conventions for wiring up resources into views and urls can be handled automatically, using Router
classes. All we need to do is register the appropriate resources with a router, and let it do the rest. Here's our re-wired urls.py
file.
from blog import resources
-from djangorestframework.routers import DefaultRouter
+from rest_framework.routers import DefaultRouter
router = DefaultRouter()
router.register(resources.BlogPostResource)