【问题标题】:Can a radio input send an integer to Django with POST?无线电输入可以通过 POST 向 Django 发送整数吗?
【发布时间】:2018-11-28 18:30:58
【问题描述】:

我想给出三个用单词表示但要发布数字的选择:

<form method="POST">
    {% csrf_token %}
    <div class="btn-group" data-toggle="buttons">
      <label class="btn btn-secondary">
        <input type="radio" name="intensity" id="Low" value=1 autocomplete="off"> Pale
      </label>
      <label class="btn btn-secondary">
        <input type="radio" name="intensity" id="Medium" value=5 autocomplete="off"> Medium
      </label>
      <label class="btn btn-secondary">
        <input type="radio" name="intensity" id="High" value=9 autocomplete="off"> Deep
      </label>
    </div>
</form>

但是在我看来request.POST.get('intensity') 是一个字符串。我需要手动转换它还是缺少一些东西?

ps。我没有使用 Django 表单,目前也不想使用它。

【问题讨论】:

    标签: html django python-3.x input radio-button


    【解决方案1】:

    没有。 HTTP 只处理字符串,字符串的值由服务器决定。您可以在 python 中使用int() function 转换值。

    参考: How to get int instead string from form?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多