python - 如何可视化自定义Django的文件上传表单

标签 python django user-interface file-upload customization

我的 Django 网站上有一个使用他们的表单的小型文件上传系统。不幸的是,因为它直接从 django 表单中获取,所以我无法格式化它,或者根本无法更改“选择文件”按钮。由于一段代码有 1000 个字,下面是让我无法编辑的代码片段 -

python -

class UploadFileForm(forms.Form):
  file  = forms.FileField()

~

  form = UploadFileForm()
  template = loader.get_template('file_upload.html')
  context = Context({ 'user': request.user, 'no_header': 'True', 'form' : form, 'applicant' : Applicant.objects.get(act_code = code)})

和 html -

<form name="upload" enctype="multipart/form-data" action="/file_upload/{{ object.act_code }}/{{ object.email }}/" method="post" style="padding:20px; margin:5px;" >
          {{ form }}
          <br/><br/><input type="submit" value="Upload" />
 </form>

无论如何都要这样做?谢谢。

最佳答案

<input type="file">元素是操作系统控件。您根本无法对其进行太多更改,在基于 WebKit 的浏览器中几乎没有任何更改。这不是 Django 的事情。有一些 JS 插件可以将文件字段替换为可以设置样式的常规文本字段和按钮组合,但除此之外,您就不走运了。

关于python - 如何可视化自定义Django的文件上传表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11767411/

相关文章:

Python OrderedDict : sort by tuple order?

python - 一维数组到二维数组的 Numpy 列表

java - JPanel 不会添加 JLabel 文本?

python-3.x - tkinter,如何获取Entry小部件的值?

java - 创建文件并将其保存到动态存储

Python 文本文件输入错误

javascript - 当我尝试使用 tensorflow.js 模型进行预测时,出现错误 : Uncaught TypeError: Cannot read property 'length' of undefined

python - 用于加载 Angular 模板的 Django Angular 文件夹结构

django - 如何从 django-celery 3 任务发送 channel 2.x 组消息?

django admin 外键字段数据添加