django-media配置

setting配置
  MEDIA_ROOT = os.path.join(BASE_DIR,"blog","media","upload")
  MEDIA_URL = "/media/"
复制代码
urls配置:
  from blogCMS import settings
  from django.views.static import serve

# media配置
    url(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT}),
    url(r'^uploadFile/$',views.uploadFile),
复制代码

假如涉及到文件上传问题,需要做如上配置

 

头像预览问题:

<div class="avator_div cc">
    <label for="avator">头像:</label>
    <img src="/static/img/default.png" class="avator_img" id="preScan">
    <input type="file" id="avator" class="avator_file">
</div>

 

复制代码
    $("#avator").change(function () {
        console.log("OK");
        var first_file = $(this)[0].files[0];
        var reader = new FileReader();
        reader.readAsDataURL(first_file);
        reader.onload=function () {
            $("#preScan").attr("src",this.result)
        }
    })
复制代码

 

posted @ 2018-08-08 09:11  篓子  阅读(186)  评论(0编辑  收藏  举报