Django view通过render将“字符串”传给页面插件时,值被截断问题

view.py中代码:

        # startTime = request.POST.get('startTime')
        startTime = '2019-10-10 01:01:01'
        endTime = request.POST.get('endTime')
        hostname = d1.hostname

        ip = d1.ip
        port = d1.port
        user = d1.user
        password = d1.password
        cmd = '/bin/python /home/db/mysql/scripts/analyze_binlog.py \''+ str(startTime) + '\' \'' +str(endTime)+'\''
        result = operation(ip, port, user, password, cmd)
        context={'status':result,'id':id,'hostname':hostname,'startTime':startTime,'endTime':endTime}
        return render(request, 'instance/binlog/show_analyze_binlog.html', context)

页面show.html

</script>
{#<div class="ibox-title">#}
  <form id="show_binlog_detail" name="show_binlog_detail" action="?" method = 'post' >
    序号:<input type="text" name="id" value={{ id }}><br>
    系统名:<input type="text" name="hostname" value={{ hostname }} ><br>
    开始时间:<input type="text" name="startTime" maxlength="19" value= {{ startTime }}><br>
    结束时间:<input type="text" name="endTime" value= {{ endTime }} ><br>
    <input type="button" id="show_binlog_detail" onclick="submitSelet('show_binlog_detail')" value="分析" />
  </form>
<table>
    {% for i in status %}
        <tr>
        <td>{{ i }}</td>
        </tr>
    {% endfor %}
</table>

view.py中startTime = '2019-10-10 01:01:01' 传给页面form中name='startTime'时值被截断成'2019-10-10'

其原因是value={{ startTime}} 没加双引号

改成:

   开始时间:<input type="text" name="startTime" maxlength="19" value= "{{ startTime }}" ><br>
    结束时间:<input type="text" name="endTime" value= "{{ endTime }}" ><br>

就不会截断。

发布了117 篇原创文章 · 获赞 20 · 访问量 33万+

猜你喜欢

转载自blog.csdn.net/u010719917/article/details/101368058