首页 > 解决方案 > 如何在 wagtail 管理员之外上传文件

问题描述

我想设置一个表单,允许用户从 Wagtail 管理面板外部上传文件(pdf、jpeg、docx 等)。但是表单将文件字段留在了我的 html 页面上。任何建议都会非常感谢!

模型.py

class FormField(AbstractFormField):
    page = ParentalKey('FormPage',
                   related_name='form_fields')
class FormPage(AbstractEmailForm):
    template = "formsubmission.html"
    file = models.FileField(upload_to='uploads/', 
    blank=True, null=True)
    submit_success = models.CharField(max_length=100, 
    blank=False, null=True)
    submit_error = models.CharField(max_length=100, 
    blank=False, null=True)

content_panels = AbstractEmailForm.content_panels + [
    FieldPanel('submit_success'),
    FieldPanel('submit_error'),
    InlinePanel('form_fields', label='Form Fields'),
    FieldPanel('file')
]

htmlpage.html

{% extends 'base.html' %}
{% load wagtailcore_tags %}
{% load static %}

{% block content %}
    <h1>page.title</h1>

    <div class="container">
        <form action="{% pageurl page %}" method="POST">
          {% csrf_token %}
          {{form.as_p}}
          <input type="submit">
      </form>
{% endblock %}

标签: djangocontent-management-systemwagtail

解决方案


推荐阅读