简体   繁体   English

如何将值从 django html 发送到 django 视图

[英]How send value from django html to django views

I want to make a section with goods in which you can "+" and "-" increase or decrease the quantity of goods And then, depending on the amount, "sell" it.我想制作一个商品部分,您可以在其中“+”和“-”增加或减少商品数量,然后根据数量“出售”它。

Now we need to pass the value {{ el.id }} to django views现在我们需要将值 {{ el.id }} 传递给 django 视图

My code: html:我的代码:html:

    <form method="POST">
    {% csrf_token %}
    {% for el in form3 %}
    {% if el.count > 0 %}
           [ {{ el.count }}шт. ] <br>
           [ {{ el.title }} ]<br>
           <a id="minus{{ el.id }}" href="#"><b>[ - ]</b></a>
           <span id="value{{ el.id }}">0</span>
            <a id="plus{{ el.id }}" href="#"><b>[ + ]</b></a>
            <br>
Function where i + or - from count
<script>
$(function(){
    var valueElement = $('#value{{ el.id }}');
    function incrementValue(e){
        valueElement.text(Math.max(parseInt(valueElement.text()) + e.data.increment, 0));
        return false;

    }
    $('#plus{{ el.id }}').bind('click', {increment: 1}, incrementValue);
    $('#minus{{ el.id }}').bind('click', {increment: -1}, incrementValue);
});
</script>
            {% endif %}
            {% endfor %}
       </form>

how can i get the values with "span id=value{{ el.id }}"我怎样才能获得“span id=value{{ el.id }}”的值

Solved解决了

    {% for el in form3 %}
    {% if el.count > 0 %}
           [ {{ el.count }}шт. ] <br>
           [ {{ el.title }} ]<br>
           <a id="minus{{ el.id }}" href="#"><b>[ - ]</b></a>
           <span id="span-value{{el.id}}">0</span>
           <a id="plus{{ el.id }}" href="#"><b>[ + ]</b></a>
        <br>
                <input type="hidden" name=name-{{el.id}} id="input-{{el.id}}" value="0">
        <script>
            $(function(){
            var valueElement = $('#span-value{{el.id}}');
            function incrementValue(e){
            valueElement.text(Math.max(parseInt(valueElement.text()) + e.data.increment, 0));
    var value = $("#span-value{{el.id}}").text();
    var lower=$("#input-{{el.id}}").val(value);
            return false;
            }
                $('#plus{{ el.id }}').bind('click', {increment: 1}, incrementValue);
                $('#minus{{ el.id }}').bind('click', {increment: -1}, incrementValue);
            });
        </script>
    {% endif %}
    {% endfor %}

use this for copy\\duplicate span value on input After this you can user request.post.dict or request.post.items() for key:values将此用于输入时的复制\\重复跨度值在此之后,您可以使用 request.post.dict 或 request.post.items() for key:values

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

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