想要学习django与REST没有休息框架 [英] Want to learn django with REST without rest framworks
问题描述
我在网上搜索,但是例子/教程填写了已经构建的解决方案。我也检查基于请求方法的过滤。我正在考虑两种方法。
urls.py有办法检查请求方法并转移到views.py中的相应方法。
或我可以添加一个预加载钩子/类来确定应用程序初始化时的请求方法,并且调用相应的方法,以覆盖urls.py行为(我的首选方法)。
如果有人可以建议一个django方式来做到这一点?
更新:我发现了一些关于SO的有趣评论如 https://stackoverflow.com/a/20898410/1230744 AND https://stackoverflow.com/a/1732520/1230744 。
我从最后得到我的问题的答案链接。可以通过使用基于类的视图+序列化。
上面链接的代码段链接给了很多例子,给出了如何只使用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.
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屋!