【问题标题】:Django - Change what 'upload file' button says in the templateDjango - 更改模板中“上传文件”按钮的内容
【发布时间】:2014-10-28 09:04:54
【问题描述】:

我有这个模型:

class uploadImage(models.Model):
    postImage = models.ImageField(upload_to=get_postImage_path, blank=True, null=True)

我为这个模型创建了一个表单。我将表单作为“imageForm”传递给我的模板。这是我的模板:

<form enctype="multipart/form-data" id='imageForm' method="post" action="/uploadImage/">{% csrf_token %}
{{ imageForm.postImage }}
<input type='submit' value='upload' />
</form>

现在,当我从浏览器转到此模板页面时,有一个按钮显示“选择文件”,在该按钮旁边,显示“未选择文件”。用户单击“选择文件”并选择文件后,“未选择文件”文本更改为文件名。

如何在用户选择图像后让按钮显示“上传图像”而不是“选择文件”,并让“未选择文件”显示“附加图像”(而不是文件名)?

【问题讨论】:

标签: django django-forms django-models


【解决方案1】:

这与 Django 无关;文件上传按钮和文本由浏览器定义。有一些解决方案,其中大多数涉及使用另一个触发上传按钮的元素。

Here's a five-minute YouTube tutorial 解决了 Django 应用程序上的问题。

This jQuery plugin 也会解决您的问题。

And this solution 使用 CSS。


此外,以下是其他解决方案和讨论的一些链接:

How to change the button text of <input type="file" />?

Labeling file upload button

HTML input file - how to translate "Choose File" and "No file Chosen"?

Change default text in input type="file"?

【讨论】:

    猜你喜欢
    • 2014-01-29
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-17
    • 1970-01-01
    • 1970-01-01
    • 2011-01-07
    相关资源
    最近更新 更多