简体   繁体   English

Django视图和URL

[英]Django Views and Urls

This is a bit long so please bear with me..... 这有点长,所以请忍受我.....

I am in the middle of building an android application. 我正在构建一个android应用程序。 I have built the client app, now I am working on the server. 我已经构建了客户端应用程序,现在正在服务器上工作。

I have decided to use Django for the server. 我决定将Django用于服务器。 Though I have already decided on the data structures, currently I am stuck with how am I supposed to send different kinds of requests from the server and how the server is supposed to handle them differently. 尽管我已经决定了数据结构,但是目前我仍然困惑于如何从服务器发送不同种类的请求以及服务器如何以不同方式处理它们。

For example: 例如:

  1. A request could be registering a new user and storing his credentials. 请求可能是注册新用户并存储其凭据。
  2. Another request could be when a user likes or dislikes a comment. 另一个请求可能是用户喜欢或不喜欢评论时。 ..... there could be few more .....可能还有更多

One way that I can think of is to first have separate "django views" for each kind of requests and then attach a "django url" to it. 我可以想到的一种方法是,首先为每种请求使用单独的“ django视图”,然后将“ django url”附加到它。 Now from the client app, a particular kind of request could be made at its specific url, and then once received at the server, "django" will automatically direct it to its view, which will then take the desired actions. 现在,从客户端应用程序,可以在其特定的URL上发出特定类型的请求,然后在服务器上接收到“ django”后,它将自动将其定向到其视图,然后它将采取所需的操作。

Please let me know if there are any better ways to do it. 如果有更好的方法,请告诉我。

Yes, that is exactly how to do it. 是的,这就是方法。

You probably want to look into Django REST framework for this. 您可能想为此研究Django REST框架

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM