形式不显示以及如何删除< li>以django形式
我有问题。为什么我的表格不显示,除了我单击提交按钮。我的代码有什么问题吗?
这是我的html代码:
<form method="POST" enctype="multipart/form-data">
<button type="submit" class="dsnupload">
<i class="large material-icons" style="font-size: 50pt; margin-top: 10px;">audiotrack</i>
<p style="font-weight: bold; color: white;">Insert file audio (mp3)</p>
{% csrf_token %}
{{form}}
</button>
</form>
form.py:
from django import forms
class Audio_store(forms.Form):
record=forms.FileField(widget=forms.FileInput(attrs={'style': 'width: 300px;', 'class': 'form-control'}))
views.py:
def homepage(request):
if request.method == "POST":
form = Audio_store(request.POST, request.FILES)
if form.is_valid():
handle_uploaded_file(request.FILES['record'])
return render(request, "homepage.html", {'form': form})
else:
return render(request, "homepage.html")
在左侧的第二个橙色按钮(插入文件音频)上有文本:
记录:
- 需要此字段。
我想删除该文本,请帮助我。
i have problem. why my form doesn't show except i clicked submit button. is that any problem with my code?
here's my html code :
<form method="POST" enctype="multipart/form-data">
<button type="submit" class="dsnupload">
<i class="large material-icons" style="font-size: 50pt; margin-top: 10px;">audiotrack</i>
<p style="font-weight: bold; color: white;">Insert file audio (mp3)</p>
{% csrf_token %}
{{form}}
</button>
</form>
form.py :
from django import forms
class Audio_store(forms.Form):
record=forms.FileField(widget=forms.FileInput(attrs={'style': 'width: 300px;', 'class': 'form-control'}))
views.py :
def homepage(request):
if request.method == "POST":
form = Audio_store(request.POST, request.FILES)
if form.is_valid():
handle_uploaded_file(request.FILES['record'])
return render(request, "homepage.html", {'form': form})
else:
return render(request, "homepage.html")
at the second orange button on the left (insert file audio) there's text :
record :
- this field is required.
i want to remove that text, please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您阅读有关Python变量的信息-has-a-value“ rel =“ nofollow noreferrer”> scopes
如果您的形式有效,则可以将用户重定向到新 page
I'll suggest you to read about python variable scopes
if your form valid it's good practice to redirect user to new page