[英]Can I pass html elements into a jinja variable?
I am trying to set up a way to automatically format an input field to use the currency function of python's locale module. 我试图建立一种自动格式化输入字段以使用python语言环境模块的货币功能的方法。 However, I am running into an issue passing references into segment of jinja.
但是,我遇到了一个将引用传递到jinja段的问题。
If I hardcode the value of the input like this it gives me my correctly formatted value: 如果我像这样对输入的值进行硬编码,它将为我提供正确格式化的值:
<input onkeyup="this.value='{{ currency(20)) }}'>
However, what I really need is instead of passing in 20, I want it to use user input, therefore I need to pass in the current value of the input field itself. 但是,我真正需要的不是传递20,而是希望它使用用户输入,因此我需要传递输入字段本身的当前值。
I tried something like : 我尝试了类似的东西:
<input onkeyup="this.value='{{ currency(this.value())) }}'>
I have also tried using document.getElementbyId and a number of other variations, problem is that none of those objects are available inside of the {{ }}. 我也尝试过使用document.getElementbyId和许多其他变体,问题是{{}}内没有这些对象。 Anyone have any sugestions, is jinja capable of doing this type of dynamic processing?
任何人都有建议,神社有能力进行这种动态处理吗?
This isn't possible because Jinja creates the HTML before the page is sent to the client and any Javascript runs. 这是不可能的,因为Jinja会在将页面发送给客户端并运行任何Javascript之前创建HTML。
The only way to do this dynamically in serverside Python would be via an AJAX call which would be very inefficient. 在服务器端Python中动态执行此操作的唯一方法是通过AJAX调用,这将非常低效。
My suggestion is you find an implementation of the currency formatting function in Javascript. 我的建议是您在Javascript中找到货币格式化功能的实现。 A quick google on this should give you lots of options.
快速谷歌应该给你很多选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.