想要学习django与REST没有休息框架 [英] Want to learn django with REST without rest framworks

查看:146
本文介绍了想要学习django与REST没有休息框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个php程序员,我已经在php中构建了一些基于REST的解决方案。现在我正在学习python / django。我想在Django中制作基于REST的解决方案(仅用于知识目的)。我不想使用任何REST框架/工具包,因为这个项目更多的是探索django / python说他们如何使用原始的REST概念。



我在网上搜索,但是例子/教程填写了已经构建的解决方案。我也检查基于请求方法的过滤。我正在考虑两种方法。



urls.py有办法检查请求方法并转移到views.py中的相应方法。

或我可以添加一个预加载钩子/类来确定应用程序初始化时的请求方法,并且调用相应的方法,以覆盖urls.py行为(我的首选方法)。



如果有人可以建议一个django方式来做到这一点?



更新:我发现了一些关于SO的有趣评论如 https://stackoverflow.com/a/20898410/1230744 AND https://stackoverflow.com/a/1732520/1230744

解决方案

我从最后得到我的问题的答案链接。可以通过使用基于类的视图+序列化。



令人愉快的路线和Django



上面链接的代码段链接给了很多例子,给出了如何只使用Django Core创建REST Api的例子。此外,我还使用序列化 https://docs.djangoproject.com/en/dev/topics / serialization / for Json encoding



(现在,如果有人喜欢,他可以标记重复该问题;))


I am a php programmer, I have built some REST based solutions in php. Now I am learning python/django. I want to make a REST based solution in Django ( only for knowledge purpose ). I do not want to use any of REST frameworks/toolkits as This project is more a exploring django/python say how they work with raw REST concept.

I searched on net, But examples/tutorial filled on already built solutions. I also checkout for request method based filtering. I am thinking of two approaches.

Either urls.py have way to check request method and transfer to respective method in views.py.
Or I can add a pre load hook/class which determine request method on application initialize, And called respective method so overriding urls.py behavior (my preferred method).

If anybody can suggest a django way to do this ?

Update : I found some interesting comments on SO, like https://stackoverflow.com/a/20898410/1230744 AND https://stackoverflow.com/a/1732520/1230744. Need to check if they can have the solution, I am searching.

解决方案

Well I get the answer of my questions finally from following link. It is possible through using Class based Views + serialization.

Restful routes and Django

Snippet links in side above link gave pretty much example to gave quite picture of how one can create a REST Api using only Django Core. Also I used serialize https://docs.djangoproject.com/en/dev/topics/serialization/ for Json encoding

( Now if anybody prefer, he can flag duplicate the question. ;) )

这篇关于想要学习django与REST没有休息框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆