形式不显示以及如何删除< li>以django形式

发布于 2025-01-30 06:40:16 字数 1493 浏览 4 评论 0原文

我有问题。为什么我的表格不显示,除了我单击提交按钮。我的代码有什么问题吗?

这是我的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.

web

i want to remove that text, please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘦怹 2025-02-06 06:40:16

我建议您阅读有关Python变量的信息-has-a-value“ rel =“ nofollow noreferrer”> scopes

def homepage(request):
    form = Audio_store()
    if request.method == "POST":
       form = Audio_store(request.POST, request.FILES)
       if form.is_valid():
          handle_uploaded_file(request.FILES['record'])
          return redirect("your_sccess_url")
    return render(request, "homepage.html", {'form': form})

如果您的形式有效,则可以将用户重定向到新 page

I'll suggest you to read about python variable scopes

def homepage(request):
    form = Audio_store()
    if request.method == "POST":
       form = Audio_store(request.POST, request.FILES)
       if form.is_valid():
          handle_uploaded_file(request.FILES['record'])
          return redirect("your_sccess_url")
    return render(request, "homepage.html", {'form': form})

if your form valid it's good practice to redirect user to new page

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文