更新照片并从 Django 的引导模式对话框中删除当前照片选项

问题描述 投票:0回答:0

我正在尝试构建一个图书浏览 Web 应用程序,该应用程序将在时间轴页面中显示个人资料图片、用户名和上传的图书照片列表。用户可以更新个人资料照片并删除当前个人资料照片。我使用了引导模式(对话框),其中给出了这两个选项(更新照片和删除当前照片)。谁能告诉我 views.py 文件中更新个人资料图片和删除个人资料图片的逻辑是什么?

books/timeline.html

{% extends 'books/base.html' %}
{% block content %} 
<!-- Welcome Area Start -->
<section class="welcome-area">
    <div>
        <!-- Single Slide -->
        <div class="single-welcome-slide bg-img bg-overlay">
            <div class="container h-100">
                <div class="row h-100 align-items-center">
                    <!-- Welcome Text -->
                    <!-- Our Team Area Start -->
                    <div class="container">
                    </div>
                    <div class="row">
                        <div class="col-12">
                            <div class="section-heading text-center wow fadeInUp" data-wow-delay="100ms"></div>
                        </div>
                    </div>
                    <div class="row">
                        <!-- Team Member Area -->
                        <div class="col-md-4 col-xl-4">
                            <div class="team-content-area text-center mb-30 wow fadeInUp" data-wow-delay="300ms">
                                <div class="member-thumb">
                                    <a href="#" data-toggle="modal" data-target="#profilePictureModal">
                                        <img src="{{ user.profile_picture.url }}"/>
                                    </a>
                                </div>
                                <br>
                            </div>
                        </div>
                        <div class="col-12 col-lg-8 col-xl-8">
                            <div class="welcome-text">
                                <h2 data-animation="bounceInDown" data-delay="900ms"> {{ user.username }} </h2>
                                <div class="hero-btn-group" data-animation="bounceInDown" data-delay="100ms">
                                    <a href="#" class="btn alime-btn mb-3 mb-sm-0 mr-4">Create New Post</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<!-- Welcome Area End -->

<!-- Profile pic modal -->
<div class="modal" id="profilePictureModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Choose Profile Photo</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <ul class="list-group">
                    <form action="" method="POST" enctype="multipart/form-data">
                        {% csrf_token %}
                        <li class="list-group-item text-center">
                            Upload Photo
                            <input type="file" name="update-propic" onchange="this.form.submit()" style="opacity: 0.0; position: absolute; top: 0; left: 0; bottom: 0; right: 0; width: 100%; height:100%;" /> 
                        </li>
                        <li class="list-group-item text-center" style="color: crimson;"> Remove Current Photo </li>
                    </form>
                </ul>
            </div>
        </div>
    </div>
</div>
{% endblock content %}
django forms bootstrap-modal
© www.soinside.com 2019 - 2024. All rights reserved.