Django REST Framework Implementation

Source: Internet
Author: User
Tags install django

Install Django REST.

Installation conditions:

  • Python (2.5, 2.6, 2.7 supported)
  • Django (1.2, 1.3, 1.4 supported)
  • Django. contrib. staticfiles (or django-staticfiles
    Django 1.2)
  • URLObject> = 2.0.0
  • Markdown> = 2.1.0 (Optional)
  • PyYAML> = 3.10 (Optional)

Use pip or easy_install

pip install djangorestframework
easy_install install djangorestframework

Or get the latest development version.

git clone git@github.com:tomchristie/django-rest-framework.git

Modify settings. py:

Add in INSTALLED_APPS

    'djangorestframework',

Modify urls. py:

from django.conf.urls.defaults import patterns, include, urlfrom djangorestframework.compat import Viewfrom djangorestframework.mixins import ResponseMixinfrom djangorestframework.renderers import DEFAULT_RENDERERSfrom djangorestframework.response import Responsefrom django.core.urlresolvers import reversefrom django.contrib import adminadmin.autodiscover()# Uncomment the next two lines to enable the admin:# from django.contrib import admin# admin.autodiscover()class ExampleView(ResponseMixin,View):        renderers=DEFAULT_RENDERERS        def get(self,request):                response=Response(200,{'description':'Some example content',                        'url':reverse('mixin-view')})                return self.render(response)urlpatterns = patterns('',    # Examples:    # url(r'^$', 'djrest.views.home', name='home'),    # url(r'^djrest/', include('djrest.foo.urls')),    # Uncomment the admin/doc line below to enable admin documentation:    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),    # Uncomment the next line to enable the admin:    # url(r'^admin/', include(admin.site.urls)),    url(r'^admin/',include(admin.site.urls)),    url(r'^$',ExampleView.as_view(),name='mixin-view'),    url(r'^demo/$','depot.views.detail'),)

Test:

Django REST Framework Official Website:

Http://django-rest-framework.org

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.