django - 如何在 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 %}
解决方案
推荐阅读
- php - Laravel 7,缺少 [Route: /xxxxx] 错误所需的参数
- flutter - 如何使标签指示器在颤动中变小?
- python - 在 Django 中调用 python 函数并在同一页面上显示结果
- javascript - 为什么父母不听 Angular 上的孩子?
- vue.js - 如何解决 Vue js 中的绑定问题
- swift - Firebase 实时数据库定价与查询
- amazon-dynamodb - DynamoDB - 根据条件放置项目
- memory-management - 不可变字符串和克隆
- asp.net-core - 如果自定义参数无效,IdentityServer4 拒绝令牌请求
- c# - 计算 RSI 以优化新元素