Django经常使用API
我创建了一个项目和5个应用程序,
现在问题是所有或任何特定用户都使用的特定API
可以帮助我
创建新的API或其他任何东西,但是我需要上述输出
I created a project and 5 applications
Now the problem is how many times the particular api is used by all or any particular user
Can any one help me
We can create new api or anything but I need output for above
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用请求/响应信号。
核心框架处理请求时发送的信号。
django.core.signals.request_started
然后添加信号接收器
Try to use request/response signals.
Signals sent by the core framework when processing a request.
django.core.signals.request_started
Then add signals receiver like this
您需要创建一个模型来保存用户的API计数。
使用django middledwares“> middlewares”> middlewares ,在process_request方法中,您可以增加如果请求是身份验证,则为用户的API计数(url和vive_name在请求对象中),否则在用户字段中使用null。
因此,您可以通过查询该模型来显示每用户API计数以及特定API的总计计数。
You need to create a model to save the API counts of the user.
Using the django middlewares, inside the process_request method, you can increment the count of API (URL and view_name are inside the request object) for a user if request is authenticated, otherwise use null in the user field.
So, you can show per-user API counts as well as total-counts of a particular API by querying that model.