想要在没有休息框架的情况下使用REST学习Django [英] Want to learn django with REST without rest frameworks
问题描述
我是一名php程序员,我已经在php中构建了一些基于REST的解决方案.现在我正在学习python/django.我想在Django中制作一个基于REST的解决方案(仅出于知识目的).我不想使用任何REST框架/工具包,因为该项目更像是django/python的探索之作,讲述了它们如何与原始REST概念一起使用.
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.
每个urls.py都可以检查请求方法并将其转移到views.py中的相应方法.
或者,我可以添加一个预加载钩子/类,该钩子/类确定应用程序初始化时的请求方法,并称为相应方法,从而覆盖urls.py行为(我的首选方法).
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).
如果有人可以建议使用django方法做到这一点?
If anybody can suggest a django way to do this?
更新:我在SO上找到了一些有趣的评论,例如 https://stackoverflow.com/a/20898410/1230744 AND https://stackoverflow.com/a/1732520/1230744 .我正在搜索是否需要检查他们是否可以找到解决方案.
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.
上面链接中的摘录链接提供了很多示例,充分展示了如何仅使用Django Core即可创建REST Api.我也使用序列化 https://docs.djangoproject.com/en/dev/topics/serialization/用于Json编码
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. ;) )
这篇关于想要在没有休息框架的情况下使用REST学习Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!