图像未使用模板Django的createview上传

时间:2018-12-11 10:52:57

标签: django

CompanyCreateView是通用视图。该文件从Django管理上载,但不从模板上载。

company_logo存储在mysql数据库中

class CompanyCreateView(CreateView):
    model = Company
    fields = ['company_name', 'company_description', 'company_email', 
    'company_website', 'company_address', 'company_phone', 'company_status', 
    'company_monthly_payment', 'company_logo']

company_form.html

 {% extends "super_admin/base.html" %}
{% load crispy_forms_tags %}
{% block content %}
    <div class="content-section">

        <form action="" method="POST">
            {% csrf_token %}
            <fieldset class="from-group">

                {% if  object.company_name.strip  %}
                    <legend class="border-bottom mb-4">Update Company</legend>
                {% else %}
                    <legend class="border-bottom mb-4">Enter New Company</legend>
                {% endif %}


                {{ form | crispy}}
            </fieldset>
            <div class="form-group">

                {% if  object.company_name.strip  %}
                    <button class="btn btn-outline-info" type="submit">Update</button>
                    <a class="btn btn-primary" href="{% url 'super-company-delete' object.id %}" role="button">Delete</a>
                {% else %}
                    <button class="btn btn-outline-info" type="submit">Save</button>
                {% endif %}


            </div>
        </form>

    </div>
{% endblock content %}

1 个答案:

答案 0 :(得分:0)

我找到了我在表单中缺少enctype的答案。只需替换表单标签

<form action="" method="POST" enctype="multipart/form-data">