我想要两个互斥字段。
一个是FileField,另一个是TextBoxField。
有没有现成的html表格我可以拿到。
我在网上搜索了一下,没有找到。
哦,我有点抱歉。。
我的意思是,我想通过Django模板来做这件事
您可以创建一个onInput事件侦听器,并使用javascript进行处理,这样,如果用户在一个字段中键入内容,就会清空另一个字段。
例如:
<form>
<label for="first">Fill This:</label>
<input type="text" name="first" id="first" oninput="run('first')"><br><br>
<label for="second">Or This:</label>
<input type="text" name="second" id="second" oninput="run('second')"><br><br>
<input type="submit" value="Submit">
</form>
<script>
function run(activeField) {
if (activeField == 'first') {
const second = document.querySelector('#second')
second.value = ''
} else {
const first = document.querySelector('#first')
first.value = ''
}
}
</script>
对于您的文本框,您可以使用以下内容:
<input type="text" name="name" placeholder="Please enter your name">
对于您的文件:
<input type="file" name="fileName">
但对于文件名,它需要加密。HTML不允许您提交带有文件的表单。但是您可以在attr中覆盖它,如下所示:
<form action="dirToForm.py" method="POST" enctype="multipart/form-data"></form>