R
R
RandomMUSTACHEO2021-09-27 20:13:46
API
RandomMUSTACHEO, 2021-09-27 20:13:46

How to pass data from html template to django rest api serializer?

There is a shipping calculator template in which the dimensions, weight and destination of the parcel are driven in.

<div class="prim">
        <div class="kalk__container">
            <div class="head">
                <div class="head__title">Заказ</div>
                <div class="sbros">
                    <a  href="#">Сбросить рассчёт</a>
                </div>
            </div>
        <div class="column">
            <div class="calc__item">
                <div class="item__title">
                    Откуда
                </div>
                <div class="item__content">
                    Белгород
                </div>
            </div>
            <div class="calc__item">
                <div class="item__title">
                    Куда
                </div>
                <div class="item__content">
                    <select class="sel">
                        <option value="1">Москва</option>
                        <option value="2">Санкт-Петербург</option>
                        <option value="3">Нижний Новгород</option>
                        <option value="4">Мытищи</option>
                    </select>
                </div>
            </div>
            <div class="calc__item">
                <div class="item__title">
                    Вес, кг
                </div>
                <input class="input" type="number"  min="1" max="25" >
            </div>
            <div class="calc__item">
                <div class="item__title">
                    Длинна, см
                </div>
                <input class="input" type="number"  min="1" max="150" >
            </div>
            <div class="calc__item">
                <div class="item__title">
                    Ширина, см
                </div>
                <input class="input" type="number"  min="1" max="150" >
            </div>
            <div class="calc__item">
                <div class="item__title">
                    Высота, см
                </div>
                <input class="input" type="number"  min="1" max="150" >
            </div>
        </div>
            <div class="add">
                <div class="text__bottom">+ Добавить упаковку</div>
        </div>
            <div class="rass">
              <div class="text__bottom">Рассчитать</div>  
            </div>
        </div>
    </div>

Enter data in the corresponding fields. It is necessary to transfer this data to the serializer.
class CalcSerializer(serializers.Serializer):
    pack_weight = serializers.IntegerField()
    pack_length = serializers.IntegerField()
    pack_width = serializers.IntegerField()
    pack_height = serializers.IntegerField()
    pack_destination = serializers.CharField()

How can I do this and are there any mistakes in what I have done now?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question