Django - 在表单验证后保持表单值填充

时间:2016-12-04 21:02:36

标签: django django-forms django-templates

当我提交表单时,由于某种原因未对表单进行验证,表单将全部显示为空白。我没有使用{{form}}来呈现完整的表单,我想让其他人自定义它。

这是表格的一部分:

File file = new File("FileToUse.txt");
FileInputStream fis = null;

    try {
        fis = new FileInputStream(file);

        System.out.println("Total file size to read (in bytes) : "
                + fis.available());

        int content;
        while ((content = fis.read()) != -1) {
            // process the content into the hashmap
        }

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (fis != null)
                fis.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
}

这是view.py

<form method="post" action="" enctype="multipart/form-data">{% csrf_token %}
    <div class="panel panel-default">
        <div class = "panel-heading">
            Informações de Contato 
        </div>
        <div class = "panel-body">
            <div class="input-group">
                <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                <input type="text" class="form-control" 
                id="id_{{ anuncioForm.nome_contato.name }}" 
                name="{{ anuncioForm.nome_contato.name }}"
                value= "{{ request.user.first_name }} {{request.user.last_name}}"
                placeholder="Nome">
            </div>
            <p class="help-text">{{ anuncioForm.nome_contato.help_text }} </p>
            <br>

            <div class="input-group">
                <span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
                <input type="text" class="form-control" 
                id="id_{{ anuncioForm.email_contato.name }}" 
                name="{{ anuncioForm.email_contato.name }}"
                value="{{ request.user.email }} " 
                placeholder="E-mail">
            </div>
            <p class="help-text">{{ anuncioForm.email_contato.help_text }} </p>
            <br>

            <div class="input-group">
                <span class="input-group-addon"><i class="glyphicon glyphicon-glyphicon glyphicon-phone"></i></span>
                <input type="text" class="form-control" 
                id="id_{{ anuncioForm.telefone_contato.name }}" 
                name="{{ anuncioForm.telefone_contato.name }}"
                placeholder="Telefone ou Celular">
            </div>
            <p class="help-text">{{ anuncioForm.telefone_contato.help_text }} </p>
        </div>
    </div>

我可以做些什么来保持填充值?

0 个答案:

没有答案
相关问题