图像未使用模板Django的createview上传 [英] Image does not upload using createview from template django

查看:35
本文介绍了图像未使用模板Django的createview上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

CompanyCreateView is a generic view. The file uploads from django administration but does not upload from template.

company_logo存储在mysql数据库中

company_logo is stored in mysql database

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

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 %}

推荐答案

我找到了我缺少形式的enctype的答案.只需替换表单标签

I have found the answer i was missing enctype in form. Just replace the form tag

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

这篇关于图像未使用模板Django的createview上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆