2.6.5 优化头像上传功能

Posted yaoyuanchun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2.6.5 优化头像上传功能相关的知识,希望对你有一定的参考价值。

目录

1.复制js文件

cp  ~/DjangoPracticeProject/layer-v3.0.1/layer/layer.js  static/js/

cp -a  ~/DjangoPracticeProject/layer-v3.0.1/layer/skin static/js/ 

 

2.编辑 templates/account/myself.html

导入js文件,增加弹窗功能

技术图片
{% extends "base.html" %}
{% load staticfiles%}
{% block title %}myinforation{% endblock %}
{% block content %}
<script>
    function upload_image_layer(){
        layer.open({
            title:"上传头像",
            area:[900px , 600px],
            type:2,
            content:"{% url ‘account:my_image‘ %}",
    
        });
    }
</script>
<div class ="row text-center vertical-middle-sm">
<h1>My Information</h1>
<div class ="row">

<div class="col-md-6">

    <div class="row">
        <div class ="col-md-4 text-right"><span>username:</span></div>
        <div class="col-md-8 text-left">{{ user.username}}</div>
    </div>

    <div class ="row">
        <div class="col-md-4 text-right"><span>email:</span></div>
        <div class="col-md-8 text-left">{{ user.email}}</div>
    </div>

    <div class ="row">
        <div class="col-md-4 text-right"><span>birth:</span></div>
        <div class ="col-md-8 text-left">{{ userprofile.birth}}</div>
    </div>

    <div class ="row">
        <div class="col-md-4 text-right"><span>phone:</span></div>
        <div class="col-md-8 text-left">{{ userprofile.phone}}</div>
    </div>

    <div class="row">
        <div class="col-md-4 text-right"><span>school:</span></div>
        <div class="col-md-8 text-left">{{userinfo.school}}</div>
    </div>

    <div class ="row">
        <div class ="col-md-4 text-right"><span>company:</span></div>
        <div class="col-md-8 text-left">{{userinfo.company}}</div>
    </div>

    <div class ="row">
        <div class ="col-md-4 text-right"><span>profession:</span></div>
        <div class ="col-md-8 text-left">{{userinfo.profession}}</div>
    </div>

    <div class ="row">
        <div class="col-md-4 text-right"><span>address:</span></div>
        <div class ="col-md-8 text-left">{{ userinfo.address}}</div>
    </div>

    <div class ="row">
        <div class ="col-md-4 text-right"><span>about:</span></div>
        <div class ="col-md-8 text-left">{{ userinfo.aboutme}}</div>
    </div>
<a href="{% url ‘account:edit_my_information‘ %}"><button class="btn btn-primary btn-lg">edit my information</button></a>
</div>

    <div class ="col-md-6">
        <div style="margin-right:100px">
            {% if userinfo.photo %}
                <img src="{{userinfo.photo | striptags }}" class="img-circle" id="my_photo" name="user_face">
            {% else %}
                <img name ="user_face" src="{% static ‘images/pig.jpg‘ %}" class="img-circle" width="270px" id="my_photo">
            {% endif %}
        </div>
        <div style="margin-right: 100px"><button class="btn btn-primary btn-lg" id="upload_image" onclick="upload_image_layer()">upload my photo</button></div>
    </div>
</div>
</div>
<script type="text/javascript" src=‘{% static "js/jquery-3.4.1.min.js" %}‘></script>
<script type="text/javascript" src=‘{% static "js/layer.js" %}‘></script>
{% endblock %}
View Code

 

以上是关于2.6.5 优化头像上传功能的主要内容,如果未能解决你的问题,请参考以下文章

如何java中实现上传头像功能?

如何java中实现上传头像功能?

富头像上传编辑器----很好用的上传照片和拍照功能

java web实现上传头像功能,

信小程序上传头像

django头像上传预览功能