RESTful API和Django中的urlpatterns路由器之间的区别 [英] Differences between RESTful API and urlpatterns router in Django
问题描述
是Web开发的新手,想知道它们之间的区别:
Am new to web developpement and wondering the differences between:
Django Restful API
Django Restful API
和
标准Django URL路由器
standard Django URL routers
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.index, name='Index'),
url(r'^getvalue/$', views.get_points, name='Get Points'),
url(r'^putvalue/$', views.put_points, name='Put Points'),
]
与Javascript组件进行交互时设置Django Restful API有什么好处,因为两者都是JSON发送URL?
What are the benefits of setting Django restful API when interacting with Javascript components since both are JSON sending URL ?
推荐答案
问了问题已经有一段时间了,但是我想我也应该提供一个答案,因为它也困扰着我.
It was quite some time since the question had been asked, but I thought I'd provide an answer as it bothered me as well.
您要使用Django路由器的主要原因是方便:一旦声明一次,便不必像在urls_patterns中持久声明url那样麻烦.
The main reason why you want to use Django's routers is convenience: once you declared them once, you don't have to go through the same cumbersomeness as persistent declaration of urls in urls_patterns.
但是,如果出于任何原因要使用特定的硬编码url,仍然可以使用url_patterns.
However, the url_patterns can still be used if for any reason you want to have a specific hard-coded url.
这篇关于RESTful API和Django中的urlpatterns路由器之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!