首页 \ 问答 \ Django:通过自定义模板标签用户输入修改数据?(Django: modifying data with user input through custom template tag?)

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

是否可以通过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?

Thank you in advance.


原文:https://stackoverflow.com/questions/31281119
更新时间:2023-01-11 14:01

最满意答案

你的变量是'btn',但你试图附加'$ btn'。 调和变量并且它应该有效,假设你已经添加了按钮对象的属性... innerHTML et al。


Your variable is 'btn', but you're trying to append '$btn'. Reconcile the variables and it should work, assuming you've added the button object's properties...innerHTML et al.

相关问答

更多
  • 你的变量是'btn',但你试图附加'$ btn'。 调和变量并且它应该有效,假设你已经添加了按钮对象的属性... innerHTML et al。 Your variable is 'btn', but you're trying to append '$btn'. Reconcile the variables and it should work, assuming you've added the button object's properties...innerHTML et al.
  • 事实证明我的一些css干扰了灯箱。 这个元素导致了这个问题: img { min-height: 100%; width: auto; } Turns out there was some of my own css interfering with lightbox. This element caused the issue: img { min-height: 100%; width: auto; }
  • 因此,如果您要在owl滑块包含的图像上初始化featherlight插件,我认为问题将出现在时机上。 看看这支笔 $(document).ready(function(){ var carousel = $('.owl-carousel').owlCarousel({ loop:true, margin:10, nav:true, responsive:{ 0:{ items:1 }, 600:{ ...
  • 将下载按钮的标记添加到灯箱使用的模板中。 Lightbox劫持了插件的所有点击,因此您必须为新标记添加事件处理程序。 在您添加标记的相同启动功能中执行此操作。您可以使用 window.open() 在新标签中打开链接。 然后,您可以基于填充链接 this.album[this.currentImageIndex].link 稍后在updateDetails函数中。 Add your markup for the download button to the template that lightbox ...
  • 您的单击处理程序在类为img的
    元素上定义。 因此,您尝试从
    元素而不是元素获取src属性: $(".img").click(function(){ // In this function, $(this) refers to
    (not ) } 如果您确实需要将click处理程序放在
    元素上,请尝试以下操作: $(".img").click(function(){ var address= ...
  • 恕我直言: 单步形式(或多步形式的第一步) 详细信息(放大的图形或对某物的深入描述) 确认或其他反馈信息 理想情况下,对于每一种,您都会优雅地降级为完整的独立URL / HTML资源。 这提供了书签功能(假设您的lightbox不做历史管理)以及搜索引擎可爬行性。 如果您确实选择使用它们,则一致使用它们至关重要。 由于它们基本上是一种新的UI模式,用户期望(潜意识地)能够理解你如何应用模式。 这增强了他们对网站的信任度和预测网站行为的能力。 Acceptable uses, IMHO: single-ste ...
  • 我把播放按钮放在标题中。 您可以通过替换以下选择器$('.tos-caption')将其放置在模式中的位置。 var tos = $('#xmpl3 a').tosrus({ buttons: false, caption: { add: true }, pagination: { add: true, type: 'thumbnails' }, slides: { scale: 'fill' ...
  • Lightbox2没有任何公共事件。 您最好的选择是使用包含您可以订阅的公共事件的脚本。 我会推荐Fancybox或Colorbox 。 使用Fancybox,您只需要在Fancybox完成打开时调用的onComplete函数中添加代码。 请注意,这两个都使用jQuery,但只要您使用noConflict() ,这应该不是问题。 Lightbox2 doesn't have any public event for that. Your best bet is to use a script that ha ...
  • 最简单的方法是查看插件的来源。 看来,它有自己的定义: https : //github.com/jbutz/bootstrap-lightbox/blob/master/js/bootstrap-lightbox.js#L318 您可以使用'data-image'属性使灯箱更新其内容。 最简单的方法可能是编写一个小脚本,使用灯箱ID获取所有图像,并将data-image属性设置为文件名中没有'_thumb'的内容(例如通过正则表达式) The easiest way would be to look at ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)