Django:通过自定义模板标签修改用户输入的数据? [英] Django: modifying data with user input through custom template tag?

查看:322
本文介绍了Django:通过自定义模板标签修改用户输入的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以通过Django中的自定义模板标签修改数据吗?更具体地说,我有一个名为Shift的模型,其数据要以日历表格显示。我认为使用自定义的包含标签是最好的方式,但我也希望用户能够点击转移和买/卖转移(从而修改数据库)。我的猜测是,你不能用包含标签来做到这一点,但是如果我要从头开始编写一个不同类型的自定义模板标签,那么这是可能的吗?如果是这样,你能否指引一些资源来解决如何编写这样的标签?

Is it possible to modify data through custom template tag in Django? More specifically, I have a model named Shift whose data I want to display in a calendar form. I figured using a custom inclusion tag is the best way to go about it, but I also want users to be able to click on a shift and buy/sell the shift (thus modifying the database). My guess is that you can't do this with an inclusion tag, but if I were to write a different type of custom template tag from the ground up, would this be possible? If so, can you direct me to a few resources that address how to write such a tag?

提前谢谢。

推荐答案

这种类型的逻辑不属于模板标签。它属于一个视图,它将响应AJAX请求并返回一个JSONResponse。您将需要一些JavaScript来处理基于输入的请求。

This type of logic does not belong in a template tag. It belongs in a view that will respond to AJAX requests and return a JSONResponse. You'll need some javascript to handle making the request based on the input as well.

这篇关于Django:通过自定义模板标签修改用户输入的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆