如何使用 font Awesome 图标作为 django 模板的文件上传输入字段作为引导程序?

发布于 2025-01-16 01:56:33 字数 1350 浏览 2 评论 0原文

我使用 bootstrap 作为模板。该表单被设计为字体很棒的图标将成为设计中的文件上传字段。

有什么办法可以做到吗?我对此一无所知。我在这里分享模板代码。如果有人能帮助我,我将不胜感激。

谢谢。

  <form method="POST" action="{% url '' %}">
    {% csrf_token %}
    <div class="icons">
      <div class="row">
        <div class="col-4">
          <a href="#">
            <i class="fa fa-picture-o" aria-hidden="true"></i>
            <p>Gallery</p>
          </a>
        </div>
        <div class="col-4">
          <a href="#">
            <i class="fa fa-camera" aria-hidden="true"></i>
            <p>Camera</p>
          </a>
        </div>
        <div class="col-4">
          <a
            class=""
            href="#"
          >
            <i class="fa fa-microphone" aria-hidden="true"></i>
            <p>Audio</p>
          </a>
        </div>
      </div>
    </div>

    
    <div class="mb-3">
      <textarea
        class="form-control"
        id="exampleFormControlTextarea1"
        rows="8"
        placeholder="Type your question here"
        name="description"
      ></textarea>
    </div>

    <button type="submit" class="btn">Submit</button>
  </form>

I am using bootstrap as the template. The form is designed as the font awesome icon will be the file upload field in the design.

Is there any way to do it? I have no idea about that. I am sharing the template code here. If anyone can help me, I will be grateful.

Thanks.

  <form method="POST" action="{% url '' %}">
    {% csrf_token %}
    <div class="icons">
      <div class="row">
        <div class="col-4">
          <a href="#">
            <i class="fa fa-picture-o" aria-hidden="true"></i>
            <p>Gallery</p>
          </a>
        </div>
        <div class="col-4">
          <a href="#">
            <i class="fa fa-camera" aria-hidden="true"></i>
            <p>Camera</p>
          </a>
        </div>
        <div class="col-4">
          <a
            class=""
            href="#"
          >
            <i class="fa fa-microphone" aria-hidden="true"></i>
            <p>Audio</p>
          </a>
        </div>
      </div>
    </div>

    
    <div class="mb-3">
      <textarea
        class="form-control"
        id="exampleFormControlTextarea1"
        rows="8"
        placeholder="Type your question here"
        name="description"
      ></textarea>
    </div>

    <button type="submit" class="btn">Submit</button>
  </form>

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

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

发布评论

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

评论(1

流殇 2025-01-23 01:56:33

我建议修改 FileInputClearableFileInput 小部件的 HTML 以选择您自己的字体真棒图标。 HTML 代码可以在 django 目录中找到:django.forms.templates.widgets。代码复杂但简短,在某个位置添加图标不会破坏任何内容。

然后,您需要创建一个新的自定义小部件并在表单类定义中使用它。这更容易,它看起来像:

class CustomFileInput(FileInput):
     template_file = '<you template file>'

要覆盖文件字段的小部件,请参阅此问题

I suggest modifying the HTML of the FileInput or ClearableFileInput widget to choose your own font awesome icon. The HTML code can be found in the django directory: django.forms.templates.widgets. The code is complex but short, and adding an icon in a place won't break anything.

Then you need to create a new custom widget and use it in your form class definition. This is much easier and it look something like:

class CustomFileInput(FileInput):
     template_file = '<you template file>'

To override the widget for a file field see this question.

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