djang-tastypie学习整理
2024-10-13 15:03:57
quick start:
配置环境(pip install):
- Python 2.7+ or Python 3.4+
- Django 1.8+
python-mimeparse
0.1.4+ (http://pypi.python.org/pypi/python-mimeparse)dateutil
(http://labix.org/python-dateutil)
1、建立model
2、应用中新建api.py
内容:
from tastypie.resources import ModelResource
from my_app.models import MyModel class MyModelResource(ModelResource):
class Meta:
queryset = MyModel.objects.all()
allowed_methods = ['get']
resource_name='mymodel' #若没有自动生成类名小写
3、主url配置:
# urls.py
from django.conf.urls import url, include
from myapp.api import EntryResource entry_resource = EntryResource() urlpatterns = [
# The normal jazz here...
url(r'^blog/', include('myapp.urls')),
url(r'^api/', include(entry_resource.urls)),#EntryResource().urls
]
4、runserver localhost:8000
浏览器输入http://localhost:8000/api/mymodel/?format=json 输出有model对象
5、尝试更多地址访问(未添加授权,不支持PUT/DELET/POST操作):
最新文章
- ubuntu14.04 安装系统
- 将CSDN和WordPress上的旧文章迁移过来
- CWebBrowser2获取html的内容
- usb驱动开发3之先看core
- 通过宏定义判断是否引入的是framework,反之则使用双引号,实用!
- sql server2014各版本对比(连接)
- CC2530之Flash映射
- PHP代码分离
- Content-Type实体首部字段
- mvc of js
- 教你使用python获得字符串的md5值
- ASP.NET Core Logging in Elasticsearch with Kibana
- 前端小白第一次使用redux存取数据练习
- Devexpress Winform MVVM
- 如何解决gerrit代码冲突
- 图像像素转换 8-bit 16-bit 32-bit游戏效果
- Python 自学基础(四)——time模块,random模块,sys模块,os模块,loggin模块,json模块,hashlib模块,configparser模块,pickle模块,正则
- js实现静态页面跳转传参
- 【网络】<;网络是怎样连接的>;笔记
- asp.net 文件上传
热门文章
- 微信小程序内嵌网页 网站生成小程序
- 描述进程的PCB
- Python自动化--语言基础2--运算符、格式化输出、条件语句、循环语句、列表、元组
- 【学习笔记】Spring中的BeanFactory和ApplicationContext 以及 Bean的生命周期(Y2-3-2)
- IM开发基础知识补课:正确理解前置HTTP SSO单点登陆接口的原理
- spark RDD,DataFrame,DataSet 介绍
- 使用Git的hook实现代码的自动部署
- 了解一下Http常见状态码、Http协议的工作特点和原理、Http请求Post与Get的区别
- 《android开发艺术探索》读书笔记(五)--RemoteViews
- nyoj 1129 Salvation 模拟