2013-11-17 22:26:41 +04:00
<!DOCTYPE html>
< html lang = "en" >
2014-07-15 18:02:49 +04:00
2014-11-25 19:04:38 +03:00
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" >
< meta charset = "utf-8" >
2017-03-27 13:20:12 +03:00
< title > Home - Django REST framework< / title >
2014-11-25 19:04:38 +03:00
< link href = "./img/favicon.ico" rel = "icon" type = "image/x-icon" >
< link rel = "canonical" href = "http://www.django-rest-framework.org/" / >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< meta name = "description" content = "Django, API, REST, Home" >
< meta name = "author" content = "Tom Christie" >
<!-- Le styles -->
< link href = "./css/prettify.css" rel = "stylesheet" >
< link href = "./css/bootstrap.css" rel = "stylesheet" >
< link href = "./css/bootstrap-responsive.css" rel = "stylesheet" >
< link href = "./css/default.css" rel = "stylesheet" >
<!-- Le HTML5 shim, for IE6 - 8 support of HTML5 elements -->
<!-- [if lt IE 9]>
< script src = "http://html5shim.googlecode.com/svn/trunk/html5.js" > < / script >
<![endif]-->
< script type = "text/javascript" >
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18852272-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
< / script >
< style >
2016-05-26 13:48:39 +03:00
#sidebarInclude img {
margin-bottom: 10px;
}
#sidebarInclude a.promo {
2014-11-25 19:04:38 +03:00
color: black;
2016-05-26 13:48:39 +03:00
}
2014-11-25 19:04:38 +03:00
@media (max-width: 767px) {
div.promo {
display: none;
}
}
< / style >
< / head >
< body onload = "prettyPrint()" class = "index-page" >
2013-11-17 22:26:41 +04:00
< div class = "wrapper" >
2014-11-25 19:04:38 +03:00
< div class = "navbar navbar-inverse navbar-fixed-top" >
2013-11-17 22:26:41 +04:00
< div class = "navbar-inner" >
< div class = "container-fluid" >
2017-05-12 19:15:00 +03:00
< a class = "repo-link btn btn-primary btn-small" href = "https://github.com/encode/django-rest-framework/tree/master" > GitHub< / a >
2014-11-25 19:04:38 +03:00
< a class = "repo-link btn btn-inverse btn-small " rel = "prev" href = "tutorial/quickstart/" >
Next < i class = "icon-arrow-right icon-white" > < / i >
< / a >
< a class = "repo-link btn btn-inverse btn-small disabled" rel = "next" >
< i class = "icon-arrow-left icon-white" > < / i > Previous
< / a >
2015-06-04 17:37:22 +03:00
< a id = "search_modal_show" class = "repo-link btn btn-inverse btn-small" href = "#mkdocs_search_modal" data-toggle = "modal" data-target = "#mkdocs_search_modal" > < i class = "icon-search icon-white" > < / i > Search< / a >
2013-11-17 22:26:41 +04:00
< a class = "btn btn-navbar" data-toggle = "collapse" data-target = ".nav-collapse" >
< span class = "icon-bar" > < / span >
< span class = "icon-bar" > < / span >
< span class = "icon-bar" > < / span >
< / a >
2014-08-02 18:29:15 +04:00
< a class = "brand" href = "http://www.django-rest-framework.org" > Django REST framework< / a >
2013-11-17 22:26:41 +04:00
< div class = "nav-collapse collapse" >
2014-11-25 19:04:38 +03:00
<!-- Main navigation -->
< ul class = "nav navbar-nav" >
2015-06-04 17:37:22 +03:00
< li class = "active" >
< a href = "." > Home< / a >
< / li >
2013-11-17 22:26:41 +04:00
< li class = "dropdown" >
2014-11-25 19:31:00 +03:00
< a href = "#" class = "dropdown-toggle" data-toggle = "dropdown" > Tutorial < b class = "caret" > < / b > < / a >
2013-11-17 22:26:41 +04:00
< ul class = "dropdown-menu" >
2014-11-25 19:04:38 +03:00
< li >
< a href = "tutorial/quickstart/" > Quickstart< / a >
< / li >
< li >
< a href = "tutorial/1-serialization/" > 1 - Serialization< / a >
< / li >
< li >
< a href = "tutorial/2-requests-and-responses/" > 2 - Requests and responses< / a >
< / li >
< li >
< a href = "tutorial/3-class-based-views/" > 3 - Class based views< / a >
< / li >
< li >
< a href = "tutorial/4-authentication-and-permissions/" > 4 - Authentication and permissions< / a >
< / li >
< li >
< a href = "tutorial/5-relationships-and-hyperlinked-apis/" > 5 - Relationships and hyperlinked APIs< / a >
< / li >
< li >
2014-11-25 19:24:47 +03:00
< a href = "tutorial/6-viewsets-and-routers/" > 6 - Viewsets and routers< / a >
2014-11-25 19:04:38 +03:00
< / li >
2016-07-14 15:05:57 +03:00
< li >
< a href = "tutorial/7-schemas-and-client-libraries/" > 7 - Schemas and client libraries< / a >
< / li >
2013-11-17 22:26:41 +04:00
< / ul >
< / li >
2014-11-25 19:04:38 +03:00
2013-11-17 22:26:41 +04:00
< li class = "dropdown" >
< a href = "#" class = "dropdown-toggle" data-toggle = "dropdown" > API Guide < b class = "caret" > < / b > < / a >
< ul class = "dropdown-menu" >
2014-11-25 19:04:38 +03:00
< li >
< a href = "api-guide/requests/" > Requests< / a >
< / li >
< li >
< a href = "api-guide/responses/" > Responses< / a >
< / li >
< li >
< a href = "api-guide/views/" > Views< / a >
< / li >
< li >
< a href = "api-guide/generic-views/" > Generic views< / a >
< / li >
< li >
< a href = "api-guide/viewsets/" > Viewsets< / a >
< / li >
< li >
< a href = "api-guide/routers/" > Routers< / a >
< / li >
< li >
< a href = "api-guide/parsers/" > Parsers< / a >
< / li >
< li >
< a href = "api-guide/renderers/" > Renderers< / a >
< / li >
< li >
< a href = "api-guide/serializers/" > Serializers< / a >
< / li >
< li >
< a href = "api-guide/fields/" > Serializer fields< / a >
< / li >
< li >
< a href = "api-guide/relations/" > Serializer relations< / a >
< / li >
2014-12-01 15:20:07 +03:00
< li >
< a href = "api-guide/validators/" > Validators< / a >
< / li >
2014-11-25 19:04:38 +03:00
< li >
< a href = "api-guide/authentication/" > Authentication< / a >
< / li >
< li >
< a href = "api-guide/permissions/" > Permissions< / a >
< / li >
< li >
< a href = "api-guide/throttling/" > Throttling< / a >
< / li >
< li >
< a href = "api-guide/filtering/" > Filtering< / a >
< / li >
< li >
< a href = "api-guide/pagination/" > Pagination< / a >
< / li >
2015-03-06 15:05:16 +03:00
< li >
< a href = "api-guide/versioning/" > Versioning< / a >
< / li >
2014-11-25 19:04:38 +03:00
< li >
< a href = "api-guide/content-negotiation/" > Content negotiation< / a >
< / li >
2014-12-18 18:42:42 +03:00
< li >
< a href = "api-guide/metadata/" > Metadata< / a >
< / li >
2016-07-07 11:41:32 +03:00
< li >
< a href = "api-guide/schemas/" > Schemas< / a >
< / li >
2014-11-25 19:04:38 +03:00
< li >
< a href = "api-guide/format-suffixes/" > Format suffixes< / a >
< / li >
< li >
< a href = "api-guide/reverse/" > Returning URLs< / a >
< / li >
< li >
< a href = "api-guide/exceptions/" > Exceptions< / a >
< / li >
< li >
< a href = "api-guide/status-codes/" > Status codes< / a >
< / li >
< li >
< a href = "api-guide/testing/" > Testing< / a >
< / li >
< li >
< a href = "api-guide/settings/" > Settings< / a >
< / li >
2013-11-17 22:26:41 +04:00
< / ul >
< / li >
2014-11-25 19:04:38 +03:00
2013-11-17 22:26:41 +04:00
< li class = "dropdown" >
< a href = "#" class = "dropdown-toggle" data-toggle = "dropdown" > Topics < b class = "caret" > < / b > < / a >
< ul class = "dropdown-menu" >
2014-11-25 19:04:38 +03:00
< li >
< a href = "topics/documenting-your-api/" > Documenting your API< / a >
< / li >
2016-07-07 11:41:32 +03:00
< li >
< a href = "topics/api-clients/" > API Clients< / a >
< / li >
2015-03-06 15:05:16 +03:00
< li >
< a href = "topics/internationalization/" > Internationalization< / a >
< / li >
2014-11-25 19:04:38 +03:00
< li >
< a href = "topics/ajax-csrf-cors/" > AJAX, CSRF & CORS< / a >
< / li >
2015-10-28 14:35:39 +03:00
< li >
< a href = "topics/html-and-forms/" > HTML & Forms< / a >
< / li >
2014-11-25 19:04:38 +03:00
< li >
2015-06-04 17:37:22 +03:00
< a href = "topics/browser-enhancements/" > Browser Enhancements< / a >
2014-11-25 19:04:38 +03:00
< / li >
< li >
< a href = "topics/browsable-api/" > The Browsable API< / a >
< / li >
< li >
< a href = "topics/rest-hypermedia-hateoas/" > REST, Hypermedia & HATEOAS< / a >
< / li >
< li >
2017-02-25 22:59:44 +03:00
< a href = "topics/third-party-packages/" > Third Party Packages< / a >
< / li >
< li >
< a href = "topics/tutorials-and-resources/" > Tutorials and Resources< / a >
2014-11-25 19:04:38 +03:00
< / li >
< li >
< a href = "topics/contributing/" > Contributing to REST framework< / a >
< / li >
2014-12-18 16:49:50 +03:00
< li >
< a href = "topics/project-management/" > Project management< / a >
< / li >
2017-03-09 17:59:14 +03:00
< li >
< a href = "topics/jobs/" > Jobs< / a >
< / li >
2014-11-25 19:04:38 +03:00
< li >
2015-03-06 15:05:16 +03:00
< a href = "topics/3.0-announcement/" > 3.0 Announcement< / a >
2014-11-25 19:04:38 +03:00
< / li >
2014-12-01 15:20:07 +03:00
< li >
2015-03-06 15:05:16 +03:00
< a href = "topics/3.1-announcement/" > 3.1 Announcement< / a >
2014-12-01 15:20:07 +03:00
< / li >
2015-08-06 16:31:52 +03:00
< li >
< a href = "topics/3.2-announcement/" > 3.2 Announcement< / a >
< / li >
2015-10-28 14:35:39 +03:00
< li >
< a href = "topics/3.3-announcement/" > 3.3 Announcement< / a >
< / li >
2016-07-14 15:05:57 +03:00
< li >
< a href = "topics/3.4-announcement/" > 3.4 Announcement< / a >
< / li >
2016-10-20 18:31:37 +03:00
< li >
< a href = "topics/3.5-announcement/" > 3.5 Announcement< / a >
< / li >
2017-03-09 17:59:14 +03:00
< li >
< a href = "topics/3.6-announcement/" > 3.6 Announcement< / a >
< / li >
2017-10-06 15:06:25 +03:00
< li >
< a href = "topics/3.7-announcement/" > 3.7 Announcement< / a >
< / li >
2018-04-03 16:54:40 +03:00
< li >
< a href = "topics/3.8-announcement/" > 3.8 Announcement< / a >
< / li >
2014-11-25 19:04:38 +03:00
< li >
< a href = "topics/kickstarter-announcement/" > Kickstarter Announcement< / a >
< / li >
2016-05-26 13:48:39 +03:00
< li >
< a href = "topics/mozilla-grant/" > Mozilla Grant< / a >
< / li >
< li >
< a href = "topics/funding/" > Funding< / a >
< / li >
2014-11-25 19:04:38 +03:00
< li >
< a href = "topics/release-notes/" > Release Notes< / a >
< / li >
2013-11-17 22:26:41 +04:00
< / ul >
< / li >
2014-11-25 19:04:38 +03:00
2013-11-17 22:26:41 +04:00
< / ul >
2014-11-25 19:04:38 +03:00
< / div >
<!-- /.nav - collapse -->
2013-11-17 22:26:41 +04:00
< / div >
< / div >
< / div >
< div class = "body-content" >
< div class = "container-fluid" >
2014-11-25 19:04:38 +03:00
<!-- Search Modal -->
2015-06-04 17:37:22 +03:00
< div id = "mkdocs_search_modal" class = "modal hide fade" tabindex = "-1" role = "dialog" aria-labelledby = "myModalLabel" aria-hidden = "true" >
2014-11-25 19:04:38 +03:00
< div class = "modal-header" >
< button type = "button" class = "close" data-dismiss = "modal" aria-hidden = "true" > × < / button >
< h3 id = "myModalLabel" > Documentation search< / h3 >
< / div >
< div class = "modal-body" >
2015-08-06 16:31:52 +03:00
< form role = "form" autocomplete = "off" >
2015-06-04 17:37:22 +03:00
< div class = "form-group" >
< input type = "text" name = "q" class = "form-control" placeholder = "Search..." id = "mkdocs-search-query" >
< / div >
< / form >
< div id = "mkdocs-search-results" > < / div >
2014-11-25 19:04:38 +03:00
< / div >
< div class = "modal-footer" >
< button class = "btn" data-dismiss = "modal" aria-hidden = "true" > Close< / button >
< / div >
< / div >
2013-11-17 22:26:41 +04:00
< div class = "row-fluid" >
< div class = "span3" >
< div id = "table-of-contents" >
< ul class = "nav nav-list side-nav well sidebar-nav-fixed" >
2014-11-25 19:04:38 +03:00
2015-06-23 14:05:53 +03:00
< li class = "main" >
< a href = "#" > Django REST framework< / a >
< / li >
2014-11-25 19:04:38 +03:00
2016-06-24 13:07:42 +03:00
< li class = "" >
< a href = "#funding" > Funding< / a >
< / li >
2014-11-25 19:04:38 +03:00
< li class = "" >
< a href = "#requirements" > Requirements< / a >
< / li >
< li class = "" >
< a href = "#installation" > Installation< / a >
< / li >
< li class = "" >
< a href = "#example" > Example< / a >
< / li >
< li class = "" >
< a href = "#quickstart" > Quickstart< / a >
< / li >
< li class = "" >
< a href = "#tutorial" > Tutorial< / a >
< / li >
< li class = "" >
< a href = "#api-guide" > API Guide< / a >
< / li >
< li class = "" >
< a href = "#topics" > Topics< / a >
< / li >
< li class = "" >
< a href = "#development" > Development< / a >
< / li >
< li class = "" >
< a href = "#support" > Support< / a >
< / li >
< li class = "" >
< a href = "#security" > Security< / a >
< / li >
< li class = "" >
< a href = "#license" > License< / a >
< / li >
2015-06-23 14:05:53 +03:00
< div class = "promo" >
< hr / >
2016-05-26 13:48:39 +03:00
< div id = "sidebarInclude" >
2015-06-23 14:05:53 +03:00
< / div >
2014-11-25 19:04:38 +03:00
< / ul >
2013-11-17 22:26:41 +04:00
< / div >
< / div >
< div id = "main-content" class = "span9" >
2014-11-25 19:04:38 +03:00
2015-06-04 17:37:22 +03:00
2016-06-24 13:07:42 +03:00
< style >
.promo li a {
float: left;
width: 130px;
height: 20px;
text-align: center;
margin: 10px 30px;
padding: 150px 0 0 0;
background-position: 0 50%;
background-size: 130px auto;
background-repeat: no-repeat;
font-size: 120%;
color: black;
}
.promo li {
list-style: none;
}
< / style >
< p class = "badges" height = 20px >
2018-01-15 17:42:44 +03:00
< iframe src = "https://ghbtns.com/github-btn.html?user=encode&repo=django-rest-framework&type=watch&count=true" class = "github-star-button" allowtransparency = "true" frameborder = "0" scrolling = "0" width = "110px" height = "20px" > < / iframe >
2015-06-23 14:05:53 +03:00
2018-01-15 17:42:44 +03:00
< a href = "https://travis-ci.org/encode/django-rest-framework?branch=master" >
2017-05-12 19:15:00 +03:00
< img src = "https://secure.travis-ci.org/encode/django-rest-framework.svg?branch=master" class = "status-badge" >
2015-06-23 14:05:53 +03:00
< / a >
2013-11-17 22:26:41 +04:00
2018-04-19 19:08:26 +03:00
< a href = "https://pypi.org/project/djangorestframework/" >
2015-06-23 14:05:53 +03:00
< img src = "https://img.shields.io/pypi/v/djangorestframework.svg" class = "status-badge" >
< / a >
2013-11-17 22:26:41 +04:00
< / p >
2014-11-03 17:47:10 +03:00
< hr / >
2018-01-15 17:42:44 +03:00
< p > < strong > Note< / strong > : This is the documentation for the < strong > version 3< / strong > of REST framework. Documentation for < a href = "https://tomchristie.github.io/rest-framework-2-docs/" > version 2< / a > is also available.< / p >
2014-01-07 18:57:45 +04:00
< hr / >
< p >
2014-01-14 18:48:00 +04:00
< h1 style = "position: absolute ;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
border: 0;">Django REST Framework< / h1 >
2015-06-04 17:37:22 +03:00
< img alt = "Django REST Framework" title = "Logo by Jake 'Sid' Smith" src = "img/logo.png" width = "600px" style = "display: block; margin: 0 auto 0 auto" >
2014-01-07 18:57:45 +04:00
< / p >
2015-10-28 14:35:39 +03:00
< p > Django REST framework is a powerful and flexible toolkit for building Web APIs.< / p >
2013-11-17 22:26:41 +04:00
< p > Some reasons you might want to use REST framework:< / p >
< ul >
2018-01-15 17:42:44 +03:00
< li > The < a href = "https://restframework.herokuapp.com/" > Web browsable API< / a > is a huge usability win for your developers.< / li >
2015-03-06 15:05:16 +03:00
< li > < a href = "api-guide/authentication/" > Authentication policies< / a > including packages for < a href = "./api-guide/authentication/#django-rest-framework-oauth" > OAuth1a< / a > and < a href = "./api-guide/authentication/#django-oauth-toolkit" > OAuth2< / a > .< / li >
2014-11-25 19:04:38 +03:00
< li > < a href = "api-guide/serializers/" > Serialization< / a > that supports both < a href = "./api-guide/serializers#modelserializer" > ORM< / a > and < a href = "./api-guide/serializers#serializers" > non-ORM< / a > data sources.< / li >
< li > Customizable all the way down - just use < a href = "./api-guide/views#function-based-views" > regular function-based views< / a > if you don't need the < a href = "api-guide/generic-views/" > more< / a > < a href = "api-guide/viewsets/" > powerful< / a > < a href = "api-guide/routers/" > features< / a > .< / li >
< li > < a href = "./." > Extensive documentation< / a > , and < a href = "https://groups.google.com/forum/?fromgroups#!forum/django-rest-framework" > great community support< / a > .< / li >
2018-01-15 17:42:44 +03:00
< li > Used and trusted by internationally recognised companies including < a href = "https://www.mozilla.org/en-US/about/" > Mozilla< / a > , < a href = "https://www.redhat.com/" > Red Hat< / a > , < a href = "https://www.heroku.com/" > Heroku< / a > , and < a href = "https://www.eventbrite.co.uk/about/" > Eventbrite< / a > .< / li >
2013-11-17 22:26:41 +04:00
< / ul >
2014-01-07 18:57:45 +04:00
< hr / >
2016-06-24 13:07:42 +03:00
< h2 id = "funding" > < a class = "toclink" href = "#funding" > Funding< / a > < / h2 >
< p > REST framework is a < em > collaboratively funded project< / em > . If you use
REST framework commercially we strongly encourage you to invest in its
continued development by < strong > < a href = "topics/funding/" > signing up for a paid plan< / a > < / strong > .< / p >
2017-03-19 11:23:59 +03:00
< p > < em > Every single sign-up helps us make REST framework long-term financially sustainable.< / em > < / p >
2016-06-24 13:07:42 +03:00
< ul class = "premium-promo promo" >
< li > < a href = "http://jobs.rover.com/" style = "background-image: url(https://fund-rest-framework.s3.amazonaws.com/rover_130x130.png)" > Rover.com< / a > < / li >
< li > < a href = "https://getsentry.com/welcome/" style = "background-image: url(https://fund-rest-framework.s3.amazonaws.com/sentry130.png)" > Sentry< / a > < / li >
2016-12-09 19:07:34 +03:00
< li > < a href = "https://getstream.io/try-the-api/?utm_source=drf&utm_medium=banner&utm_campaign=drf" style = "background-image: url(https://fund-rest-framework.s3.amazonaws.com/stream-130.png)" > Stream< / a > < / li >
2017-01-27 15:57:48 +03:00
< li > < a href = "https://hello.machinalis.co.uk/" style = "background-image: url(https://fund-rest-framework.s3.amazonaws.com/Machinalis130.png)" > Machinalis< / a > < / li >
2017-10-13 16:40:30 +03:00
< li > < a href = "https://rollbar.com" style = "background-image: url(https://fund-rest-framework.s3.amazonaws.com/rollbar2.png)" > Rollbar< / a > < / li >
2018-04-18 12:33:36 +03:00
< li > < a href = "https://cadre.com" style = "background-image: url(https://fund-rest-framework.s3.amazonaws.com/cadre.png)" > Cadre< / a > < / li >
2016-06-24 13:07:42 +03:00
< / ul >
< div style = "clear: both; padding-bottom: 20px;" > < / div >
2018-04-18 12:33:36 +03:00
< p > < em > Many thanks to all our < a href = "https://fund.django-rest-framework.org/topics/funding/#our-sponsors" > wonderful sponsors< / a > , and in particular to our premium backers, < a href = "http://jobs.rover.com/" > Rover< / a > , < a href = "https://getsentry.com/welcome/" > Sentry< / a > , < a href = "https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf" > Stream< / a > , < a href = "https://hello.machinalis.co.uk/" > Machinalis< / a > , < a href = "https://rollbar.com" > Rollbar< / a > , and < a href = "https://cadre.com" > Cadre< / a > .< / em > < / p >
2016-05-28 12:51:45 +03:00
< hr / >
2015-11-04 17:59:23 +03:00
< h2 id = "requirements" > < a class = "toclink" href = "#requirements" > Requirements< / a > < / h2 >
2013-11-17 22:26:41 +04:00
< p > REST framework requires the following:< / p >
< ul >
2017-05-12 19:15:00 +03:00
< li > Python (2.7, 3.2, 3.3, 3.4, 3.5, 3.6)< / li >
2017-12-21 13:13:32 +03:00
< li > Django (1.10, 1.11, 2.0)< / li >
2013-11-17 22:26:41 +04:00
< / ul >
< p > The following packages are optional:< / p >
< ul >
2018-04-19 19:08:26 +03:00
< li > < a href = "https://pypi.org/project/coreapi/" > coreapi< / a > (1.32.0+) - Schema generation support.< / li >
< li > < a href = "https://pypi.org/project/Markdown/" > Markdown< / a > (2.1.0+) - Markdown support for the browsable API.< / li >
< li > < a href = "https://pypi.org/project/django-filter/" > django-filter< / a > (1.0.1+) - Filtering support.< / li >
2015-12-14 15:52:03 +03:00
< li > < a href = "https://github.com/maraujop/django-crispy-forms" > django-crispy-forms< / a > - Improved HTML display for filtering.< / li >
2017-05-12 19:15:00 +03:00
< li > < a href = "https://github.com/django-guardian/django-guardian" > django-guardian< / a > (1.1.1+) - Object level permissions support.< / li >
2013-11-17 22:26:41 +04:00
< / ul >
2015-11-04 17:59:23 +03:00
< h2 id = "installation" > < a class = "toclink" href = "#installation" > Installation< / a > < / h2 >
2013-11-17 22:26:41 +04:00
< p > Install using < code > pip< / code > , including any optional packages you want...< / p >
2014-11-25 19:04:38 +03:00
< pre > < code > pip install djangorestframework
2013-11-17 22:26:41 +04:00
pip install markdown # Markdown support for the browsable API.
pip install django-filter # Filtering support
< / code > < / pre >
< p > ...or clone the project from github.< / p >
2017-05-12 19:15:00 +03:00
< pre > < code > git clone git@github.com:encode/django-rest-framework.git
2013-11-17 22:26:41 +04:00
< / code > < / pre >
< p > Add < code > 'rest_framework'< / code > to your < code > INSTALLED_APPS< / code > setting.< / p >
2014-11-25 19:04:38 +03:00
< pre > < code > INSTALLED_APPS = (
2013-11-17 22:26:41 +04:00
...
2014-01-14 18:48:00 +04:00
'rest_framework',
2013-11-17 22:26:41 +04:00
)
< / code > < / pre >
< p > If you're intending to use the browsable API you'll probably also want to add REST framework's login and logout views. Add the following to your root < code > urls.py< / code > file.< / p >
2014-11-25 19:04:38 +03:00
< pre > < code > urlpatterns = [
2013-11-17 22:26:41 +04:00
...
2017-12-20 17:34:31 +03:00
url(r'^api-auth/', include('rest_framework.urls'))
2014-11-03 14:21:29 +03:00
]
2013-11-17 22:26:41 +04:00
< / code > < / pre >
2017-12-20 17:34:31 +03:00
< p > Note that the URL path can be whatever you want.< / p >
2015-11-04 17:59:23 +03:00
< h2 id = "example" > < a class = "toclink" href = "#example" > Example< / a > < / h2 >
2013-11-17 22:26:41 +04:00
< p > Let's take a look at a quick example of using REST framework to build a simple model-backed API.< / p >
2014-08-29 13:11:44 +04:00
< p > We'll create a read-write API for accessing information on the users of our project.< / p >
2013-11-17 22:26:41 +04:00
< p > Any global settings for a REST framework API are kept in a single configuration dictionary named < code > REST_FRAMEWORK< / code > . Start off by adding the following to your < code > settings.py< / code > module:< / p >
2014-11-25 19:04:38 +03:00
< pre > < code > REST_FRAMEWORK = {
2013-11-17 22:26:41 +04:00
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
]
}
< / code > < / pre >
< p > Don't forget to make sure you've also added < code > rest_framework< / code > to your < code > INSTALLED_APPS< / code > .< / p >
< p > We're ready to create our API now.
Here's our project's root < code > urls.py< / code > module:< / p >
2014-11-25 19:04:38 +03:00
< pre > < code > from django.conf.urls import url, include
2014-08-29 13:11:44 +04:00
from django.contrib.auth.models import User
from rest_framework import routers, serializers, viewsets
# Serializers define the API representation.
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ('url', 'username', 'email', 'is_staff')
2013-11-17 22:26:41 +04:00
# ViewSets define the view behavior.
class UserViewSet(viewsets.ModelViewSet):
2014-08-29 13:11:44 +04:00
queryset = User.objects.all()
serializer_class = UserSerializer
2013-11-17 22:26:41 +04:00
2013-12-15 00:44:09 +04:00
# Routers provide an easy way of automatically determining the URL conf.
2013-11-17 22:26:41 +04:00
router = routers.DefaultRouter()
router.register(r'users', UserViewSet)
# Wire up our API using automatic URL routing.
2014-12-05 12:44:35 +03:00
# Additionally, we include login URLs for the browsable API.
2014-08-29 13:11:44 +04:00
urlpatterns = [
2013-11-17 22:26:41 +04:00
url(r'^', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
2014-08-29 13:11:44 +04:00
]
2013-11-17 22:26:41 +04:00
< / code > < / pre >
2014-08-29 13:11:44 +04:00
< p > You can now open the API in your browser at < a href = "http://127.0.0.1:8000/" > http://127.0.0.1:8000/< / a > , and view your new 'users' API. If you use the login control in the top right corner you'll also be able to add, create and delete users from the system.< / p >
2015-11-04 17:59:23 +03:00
< h2 id = "quickstart" > < a class = "toclink" href = "#quickstart" > Quickstart< / a > < / h2 >
2014-11-25 19:04:38 +03:00
< p > Can't wait to get started? The < a href = "tutorial/quickstart/" > quickstart guide< / a > is the fastest way to get up and running, and building APIs with REST framework.< / p >
2015-11-04 17:59:23 +03:00
< h2 id = "tutorial" > < a class = "toclink" href = "#tutorial" > Tutorial< / a > < / h2 >
2013-11-17 22:26:41 +04:00
< p > The tutorial will walk you through the building blocks that make up REST framework. It'll take a little while to get through, but it'll give you a comprehensive understanding of how everything fits together, and is highly recommended reading.< / p >
< ul >
2014-11-25 19:04:38 +03:00
< li > < a href = "tutorial/1-serialization/" > 1 - Serialization< / a > < / li >
< li > < a href = "tutorial/2-requests-and-responses/" > 2 - Requests & Responses< / a > < / li >
2016-07-14 15:05:57 +03:00
< li > < a href = "tutorial/3-class-based-views/" > 3 - Class-based views< / a > < / li >
2014-11-25 19:04:38 +03:00
< li > < a href = "tutorial/4-authentication-and-permissions/" > 4 - Authentication & permissions< / a > < / li >
< li > < a href = "tutorial/5-relationships-and-hyperlinked-apis/" > 5 - Relationships & hyperlinked APIs< / a > < / li >
< li > < a href = "tutorial/6-viewsets-and-routers/" > 6 - Viewsets & routers< / a > < / li >
2016-07-14 15:05:57 +03:00
< li > < a href = "tutorial/7-schemas-and-client-libraries/" > 7 - Schemas & client libraries< / a > < / li >
2013-11-17 22:26:41 +04:00
< / ul >
2018-01-15 17:42:44 +03:00
< p > There is a live example API of the finished tutorial API for testing purposes, < a href = "https://restframework.herokuapp.com/" > available here< / a > .< / p >
2015-11-04 17:59:23 +03:00
< h2 id = "api-guide" > < a class = "toclink" href = "#api-guide" > API Guide< / a > < / h2 >
2013-11-17 22:26:41 +04:00
< p > The API guide is your complete reference manual to all the functionality provided by REST framework.< / p >
< ul >
2014-11-25 19:04:38 +03:00
< li > < a href = "api-guide/requests/" > Requests< / a > < / li >
< li > < a href = "api-guide/responses/" > Responses< / a > < / li >
< li > < a href = "api-guide/views/" > Views< / a > < / li >
< li > < a href = "api-guide/generic-views/" > Generic views< / a > < / li >
< li > < a href = "api-guide/viewsets/" > Viewsets< / a > < / li >
< li > < a href = "api-guide/routers/" > Routers< / a > < / li >
< li > < a href = "api-guide/parsers/" > Parsers< / a > < / li >
< li > < a href = "api-guide/renderers/" > Renderers< / a > < / li >
< li > < a href = "api-guide/serializers/" > Serializers< / a > < / li >
< li > < a href = "api-guide/fields/" > Serializer fields< / a > < / li >
2014-12-01 15:20:07 +03:00
< li > < a href = "api-guide/relations/" > Serializer relations< / a > < / li >
< li > < a href = "api-guide/validators/" > Validators< / a > < / li >
2014-11-25 19:04:38 +03:00
< li > < a href = "api-guide/authentication/" > Authentication< / a > < / li >
< li > < a href = "api-guide/permissions/" > Permissions< / a > < / li >
< li > < a href = "api-guide/throttling/" > Throttling< / a > < / li >
< li > < a href = "api-guide/filtering/" > Filtering< / a > < / li >
< li > < a href = "api-guide/pagination/" > Pagination< / a > < / li >
2015-03-06 15:05:16 +03:00
< li > < a href = "api-guide/versioning/" > Versioning< / a > < / li >
2014-11-25 19:04:38 +03:00
< li > < a href = "api-guide/content-negotiation/" > Content negotiation< / a > < / li >
2014-12-18 18:42:42 +03:00
< li > < a href = "api-guide/metadata/" > Metadata< / a > < / li >
2016-07-15 01:10:35 +03:00
< li > < a href = "api-guide/schemas/" > Schemas< / a > < / li >
2014-11-25 19:04:38 +03:00
< li > < a href = "api-guide/format-suffixes/" > Format suffixes< / a > < / li >
< li > < a href = "api-guide/reverse/" > Returning URLs< / a > < / li >
< li > < a href = "api-guide/exceptions/" > Exceptions< / a > < / li >
< li > < a href = "api-guide/status-codes/" > Status codes< / a > < / li >
< li > < a href = "api-guide/testing/" > Testing< / a > < / li >
< li > < a href = "api-guide/settings/" > Settings< / a > < / li >
2013-11-17 22:26:41 +04:00
< / ul >
2015-11-04 17:59:23 +03:00
< h2 id = "topics" > < a class = "toclink" href = "#topics" > Topics< / a > < / h2 >
2013-11-17 22:26:41 +04:00
< p > General guides to using REST framework.< / p >
< ul >
2014-11-25 19:04:38 +03:00
< li > < a href = "topics/documenting-your-api/" > Documenting your API< / a > < / li >
2016-07-14 15:05:57 +03:00
< li > < a href = "topics/api-clients/" > API Clients< / a > < / li >
2015-10-28 14:35:39 +03:00
< li > < a href = "topics/internationalization/" > Internationalization< / a > < / li >
2014-11-25 19:04:38 +03:00
< li > < a href = "topics/ajax-csrf-cors/" > AJAX, CSRF & CORS< / a > < / li >
2015-10-28 14:35:39 +03:00
< li > < a href = "topics/html-and-forms/" > HTML & Forms< / a > < / li >
2014-11-25 19:04:38 +03:00
< li > < a href = "topics/browser-enhancements/" > Browser enhancements< / a > < / li >
< li > < a href = "topics/browsable-api/" > The Browsable API< / a > < / li >
< li > < a href = "topics/rest-hypermedia-hateoas/" > REST, Hypermedia & HATEOAS< / a > < / li >
2017-02-25 22:59:44 +03:00
< li > < a href = "topics/third-party-packages/" > Third Party Packages< / a > < / li >
< li > < a href = "topics/tutorials-and-resources/" > Tutorials and Resources< / a > < / li >
2014-11-25 19:04:38 +03:00
< li > < a href = "topics/contributing/" > Contributing to REST framework< / a > < / li >
2014-12-18 16:49:50 +03:00
< li > < a href = "topics/project-management/" > Project management< / a > < / li >
2014-12-01 15:20:07 +03:00
< li > < a href = "topics/3.0-announcement/" > 3.0 Announcement< / a > < / li >
2015-03-06 15:05:16 +03:00
< li > < a href = "topics/3.1-announcement/" > 3.1 Announcement< / a > < / li >
2015-08-06 16:31:52 +03:00
< li > < a href = "topics/3.2-announcement/" > 3.2 Announcement< / a > < / li >
2015-10-28 14:35:39 +03:00
< li > < a href = "topics/3.3-announcement/" > 3.3 Announcement< / a > < / li >
2016-07-14 15:05:57 +03:00
< li > < a href = "topics/3.4-announcement/" > 3.4 Announcement< / a > < / li >
2016-10-20 18:31:37 +03:00
< li > < a href = "topics/3.5-announcement/" > 3.5 Announcement< / a > < / li >
2017-03-09 19:16:37 +03:00
< li > < a href = "topics/3.6-announcement/" > 3.6 Announcement< / a > < / li >
2017-10-06 15:06:25 +03:00
< li > < a href = "topics/3.7-announcement/" > 3.7 Announcement< / a > < / li >
2018-04-03 16:54:40 +03:00
< li > < a href = "topics/3.8-announcement/" > 3.8 Announcement< / a > < / li >
2014-11-25 19:04:38 +03:00
< li > < a href = "topics/kickstarter-announcement/" > Kickstarter Announcement< / a > < / li >
2016-05-26 13:48:39 +03:00
< li > < a href = "topics/mozilla-grant/" > Mozilla Grant< / a > < / li >
< li > < a href = "topics/funding/" > Funding< / a > < / li >
2014-11-25 19:04:38 +03:00
< li > < a href = "topics/release-notes/" > Release Notes< / a > < / li >
2017-02-25 22:59:44 +03:00
< li > < a href = "topics/jobs/" > Jobs< / a > < / li >
2013-11-17 22:26:41 +04:00
< / ul >
2015-11-04 17:59:23 +03:00
< h2 id = "development" > < a class = "toclink" href = "#development" > Development< / a > < / h2 >
2014-11-25 19:04:38 +03:00
< p > See the < a href = "topics/contributing/" > Contribution guidelines< / a > for information on how to clone
2014-08-28 20:33:56 +04:00
the repository, run the test suite and contribute changes back to REST
Framework.< / p >
2015-11-04 17:59:23 +03:00
< h2 id = "support" > < a class = "toclink" href = "#support" > Support< / a > < / h2 >
2018-01-15 17:42:44 +03:00
< p > For support please see the < a href = "https://groups.google.com/forum/?fromgroups#!forum/django-rest-framework" > REST framework discussion group< / a > , try the < code > #restframework< / code > channel on < code > irc.freenode.net< / code > , search < a href = "https://botbot.me/freenode/restframework/" > the IRC archives< / a > , or raise a question on < a href = "https://stackoverflow.com/" > Stack Overflow< / a > , making sure to include the < a href = "https://stackoverflow.com/questions/tagged/django-rest-framework" > 'django-rest-framework'< / a > tag.< / p >
2017-02-03 19:54:41 +03:00
< p > For priority support please sign up for a < a href = "https://fund.django-rest-framework.org/topics/funding/" > professional or premium sponsorship plan< / a > .< / p >
2013-11-17 22:26:41 +04:00
< p > For updates on REST framework development, you may also want to follow < a href = "https://twitter.com/_tomchristie" > the author< / a > on Twitter.< / p >
< p > < a style = "padding-top: 10px" href = "https://twitter.com/_tomchristie" class = "twitter-follow-button" data-show-count = "false" > Follow @_tomchristie< / a >
< script > ! function ( d , s , id ) { var js , fjs = d . getElementsByTagName ( s ) [ 0 ] ; if ( ! d . getElementById ( id ) ) { js = d . createElement ( s ) ; js . id = id ; js . src = "//platform.twitter.com/widgets.js" ; fjs . parentNode . insertBefore ( js , fjs ) ; } } ( document , "script" , "twitter-wjs" ) ; < / script > < / p >
2015-11-04 17:59:23 +03:00
< h2 id = "security" > < a class = "toclink" href = "#security" > Security< / a > < / h2 >
2013-11-17 22:26:41 +04:00
< p > If you believe you’ ve found something in Django REST framework which has security implications, please < strong > do not raise the issue in a public forum< / strong > .< / p >
< p > Send a description of the issue via email to < a href = "mailto:rest-framework-security@googlegroups.com" > rest-framework-security@googlegroups.com< / a > . The project maintainers will then work with you to resolve any issues where required, prior to any public disclosure.< / p >
2015-11-04 17:59:23 +03:00
< h2 id = "license" > < a class = "toclink" href = "#license" > License< / a > < / h2 >
2017-03-09 17:59:14 +03:00
< p > Copyright (c) 2011-2017, Tom Christie
2013-11-17 22:26:41 +04:00
All rights reserved.< / p >
2014-01-14 18:48:00 +04:00
< p > Redistribution and use in source and binary forms, with or without
2013-11-17 22:26:41 +04:00
modification, are permitted provided that the following conditions are met:< / p >
2014-01-14 18:48:00 +04:00
< p > Redistributions of source code must retain the above copyright notice, this
2013-11-17 22:26:41 +04:00
list of conditions and the following disclaimer.
2014-01-14 18:48:00 +04:00
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
2013-11-17 22:26:41 +04:00
other materials provided with the distribution.< / p >
2014-01-14 18:48:00 +04:00
< p > THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2013-11-17 22:26:41 +04:00
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.< / p >
2015-06-04 17:37:22 +03:00
2015-06-23 14:05:53 +03:00
< / div > <!-- /span -->
< / div > <!-- /row -->
< / div > <!-- /.fluid - container -->
< / div > <!-- /.body content -->
2014-11-25 19:04:38 +03:00
< div id = "push" > < / div >
2015-06-23 14:05:53 +03:00
< / div > <!-- /.wrapper -->
2013-11-17 22:26:41 +04:00
< footer class = "span12" >
2015-10-28 14:35:39 +03:00
< p > Documentation built with < a href = "http://www.mkdocs.org/" > MkDocs< / a > .
2014-11-25 19:04:38 +03:00
< / p >
2013-11-17 22:26:41 +04:00
< / footer >
2014-11-25 19:04:38 +03:00
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
< script src = "./js/jquery-1.8.1-min.js" > < / script >
< script src = "./js/prettify-1.0.js" > < / script >
< script src = "./js/bootstrap-2.1.1-min.js" > < / script >
2016-05-26 13:48:39 +03:00
< script src = "https://fund.django-rest-framework.org/sidebar_include.js" > < / script >
2015-06-04 17:37:22 +03:00
< script > var base _url = '.' ; < / script >
< script src = "./mkdocs/js/require.js" > < / script >
2014-12-11 12:55:10 +03:00
< script src = "./js/theme.js" > < / script >
2014-11-25 19:04:38 +03:00
< script >
var shiftWindow = function() {
scrollBy(0, -50)
};
2015-06-23 14:05:53 +03:00
2014-11-25 19:04:38 +03:00
if (location.hash) shiftWindow();
window.addEventListener("hashchange", shiftWindow);
$('.dropdown-menu').on('click touchstart', function(event) {
event.stopPropagation();
});
2015-06-23 14:05:53 +03:00
// Dynamically force sidenav/dropdown to no higher than browser window
$('.side-nav, .dropdown-menu').css('max-height', window.innerHeight - 130);
2014-11-25 19:04:38 +03:00
$(function() {
$(window).resize(function() {
2015-06-23 14:05:53 +03:00
$('.side-nav, .dropdown-menu').css('max-height', window.innerHeight - 130);
2013-11-17 22:26:41 +04:00
});
2014-11-25 19:04:38 +03:00
});
< / script >
< / body >
2013-11-17 22:26:41 +04:00
2014-11-25 19:04:38 +03:00
< / html >