django 写api

1.建立views_api.py文件, 编写foo方法

from django.http import JsonResponse
from django.core.paginator import Paginator ,PageNotAnInteger ,EmptyPage
from django.views.decorators.csrf import  csrf_exempt

def foo(req):
    return JsonResponse({'status': 0, 'msg': 'success'})

2.urls.py配置接口路径

from backend import views_api

urlpatterns = [
    url(r'^api/', views_api.foo),
]

3.调用

访问: http://127.0.0.1:8000/api/foo

你可能感兴趣的:(python)