Django REST框架实现

安装Django REST.

安装条件:

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

使用pip或者easy_install

	pip install djangorestframework
	easy_install install djangorestframework
或者获取最新开发版

	git clone [email protected]:tomchristie/django-rest-framework.git

修改settings.py:

INSTALLED_APPS 中添加

	    'djangorestframework',
修改urls.py:

from django.conf.urls.defaults import patterns, include, url

from djangorestframework.compat import View
from djangorestframework.mixins import ResponseMixin
from djangorestframework.renderers import DEFAULT_RENDERERS
from djangorestframework.response import Response

from django.core.urlresolvers import reverse
from django.contrib import admin
admin.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'),
)


测试:


Django REST框架实现_第1张图片

Django REST Framework官网:

http://django-rest-framework.org


你可能感兴趣的:(django,REST,url,import,include)