Browse Source

fix:修改头像资源文件不存在情况,使用默认头像

chenjunkai 6 years ago
parent
commit
33981ed787
1 changed files with 9 additions and 6 deletions
  1. 9 6
      Controller/UserManger.py

+ 9 - 6
Controller/UserManger.py

@@ -190,7 +190,7 @@ class getAvatarView(TemplateView):
         if filePath == '' or filePath == None:
         if filePath == '' or filePath == None:
             return response.json(800)
             return response.json(800)
         fullPath = os.path.join(BASE_DIR, "static", filePath).replace('\\', '/')
         fullPath = os.path.join(BASE_DIR, "static", filePath).replace('\\', '/')
-        defaultPath = os.path.join(BASE_DIR, "account/getAvatar/User/default.png").replace('\\', '/')
+        defaultPath = os.path.join(BASE_DIR, "static", "User/default.png").replace('\\', '/')
         if os.path.isfile(fullPath):
         if os.path.isfile(fullPath):
             try:
             try:
                 Imagedata = open(fullPath, 'rb').read()
                 Imagedata = open(fullPath, 'rb').read()
@@ -198,11 +198,14 @@ class getAvatarView(TemplateView):
             except Exception as e:
             except Exception as e:
                 return response.json(906, repr(e))
                 return response.json(906, repr(e))
         else:
         else:
-            # try:
-            #     Imagedata = open(defaultPath, 'rb').read()
-            #     return HttpResponse(Imagedata, content_type="image/jpeg")
-            # except Exception as e:
-            #     return response.json(906, repr(e))
+            print('----------------')
+            print(defaultPath)
+            print('----------------')
+            try:
+                Imagedata = open(defaultPath, 'rb').read()
+                return HttpResponse(Imagedata, content_type="image/jpeg")
+            except Exception as e:
+                return response.json(906, repr(e))
             return response.json(907)
             return response.json(907)