yf_ymm 5 лет назад
Родитель
Сommit
b77c065bcc
2 измененных файлов с 33 добавлено и 1 удалено
  1. 4 1
      apps/Equipment/urls.py
  2. 29 0
      apps/Equipment/views.py

+ 4 - 1
apps/Equipment/urls.py

@@ -20,7 +20,7 @@ from apps.Equipment.views import (
     Video_Upload,JKview,Person_Area_Pub,CropCount_View,Sell_Del,Pick_Del,
     Pick_New,Repertory_New_View,Park_Land,Contrast_Detail,Contrast_List,Person_View,Person_List,
     Area_Create,Area_Map,Person_Limit,Limit_View,Expert,learnDepot,Create_User,Change_Pwd,Delete_User,User_Change_Pwd,QXZ_Auto,QXZ_Value_Mqtt,QXZ_Status2, QXZ_Report_Detail2,
-    Sightsee_Photo,Pic_locat,Home_Farm)
+    Sightsee_Photo,Pic_locat,Home_Farm,Guide_Img)
 
 app_name = 'Equipment'
 
@@ -247,6 +247,9 @@ urlpatterns = [
     url(r'^home_farm$', Home_Farm.as_view(), name='home_farm'),
     
     
+    url(r'^guide_img$', Guide_Img.as_view(), name='guide_img'),
+    
+    
     
     
 

+ 29 - 0
apps/Equipment/views.py

@@ -1903,6 +1903,35 @@ class Test_Photo(ListView):
 
 
 
+class Guide_Img(ListView):
+    def get(self,request):
+        pass
+    def post(self,request):
+        # e_id = request.POST.get('id')
+        # news_sta = Article.objects.get(id=e_id)
+        guide_photo = request.FILES['upload']
+        if guide_photo:
+            print("新闻图片:", guide_photo)
+            news_photo_dir = 'media/uploads/'
+            end_name = guide_photo.name.split('.')[-1]
+            # 判断如果路径不存在,即创建路径
+            if os.path.exists(news_photo_dir) == False:
+                os.makedirs(news_photo_dir)
+            img = Image.open(guide_photo)
+            now_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
+            pic_name = now_time + '.' + end_name
+            print("pic_name:", pic_name)
+            img.save(news_photo_dir + pic_name)
+            news_photo = news_photo_dir + pic_name
+            print("new_photo:",news_photo)
+            data = {"uploaded": 1,"fileName": pic_name,"url": news_photo}
+        else:
+            new_photo = "0"
+            data = {"code": 404,"msg": "","data": {"src": news_photo}}
+        data = json.dumps(data)
+        return HttpResponse(data)
+
+
 class CKArticle_View(ListView):
     def get(self,request):
         pass