def get_List(request): if request.method == 'GET': try: data = Blog.objects.all().values() return returnJson.json_responre(data) except: # return JsonResponse({'a':'b'}) traceback.print_exc()
def get_detail(request): fid = json.loads(request.body).get('id') try: list = Blog.objects.get(id=fid) data = model_to_dict(list) return returnJson.json_responre(data) except: return returnJson.json_error()
def get_list(requset): dr = re.compile(r'<[^>]+>', re.S) articl = Blog.objects.all().order_by('id').values() list = [] for item in articl: items = item items['reContent'] = dr.sub('', item.get('content')) list.append(items) return returnJson.json_responre(list)
def user_login(request): form = LoginForm(request.POST) if not form.is_valid(): return returnJson.json_error('请输入账号密码或者正确的邮件') user = form.get_user() auth.login(request, user) token_str = Token.objects.get(user=user).key data = {'token': token_str} if user.is_active: return returnJson.json_responre(data) return returnJson.json_error('登录失败')
def uploadFile(request, **kwargs): print(request) print(request.META) if request.method == 'POST': fileform = FileForm(request.POST, request.FILES) if fileform.is_valid(): dic = fileform.cleaned_data newfile = File(fid=request.user.id, video=dic.get('file')) newfile.save() return returnJson.json_responre('success') else: return returnJson.json_error(fileform.errors)
def deleFile(requst, **kwargs): name = requst.POST.get('name') url = name[6:len(name)] print(url) patch = os.path.join(BASE_DIR, name) print(patch) if os.path.exists(patch): os.remove(patch) print(patch) try: File.objects.get(video=url).delete() return returnJson.json_responre('删除成功') except: return returnJson.json_error("删除失败") else: return returnJson.json_error("删除失败,图片不存在")
def get_list_date(request): dr = re.compile(r'<[^>]+>', re.S) articl = Blog.objects.all().order_by('-creatdate').values() dic = dict() data = [] for item in articl: item['reContent'] = dr.sub('', item.get('content')) date = item['creatdate'] dateKey = date.strftime("%Y-%m") itemData = dic.get(dateKey) if (dic.get(dateKey)) else [] itemData.append(item) dic[dateKey] = itemData for key in dic.keys(): obj = {'date': key, 'data': dic.get(key)} data.append(obj) return returnJson.json_responre(data)
def get_topi_content(request): obejct = ['json', 'pual', 'george', 'rirga'] p = Paginator(obejct, 2) p = p.page(1).object_list return returnJson.json_responre(p, safe=False)
def get_user_list(requset): if requset.method == 'GET': data = ForumUser.objects.all() data = serializers.serialize("json", data) return returnJson.json_responre(json.loads(data), safe=False)
def get_topic_content(request): print(request.POST.get('id')) fid = request.POST.get('id') model = Blog.objects.get(id=fid) u = json.dumps(model_to_dict(model), cls=returnJson.DataTimeEncoder) return returnJson.json_responre(json.loads(u), safe=False)
def post_api_login(request): form = RegisterForm(request.POST) if not form.is_valid(): return returnJson.json_error(form.errors) form.save() return returnJson.json_responre('success')
def get_userCentertitle(request): title = UserCenter.objects.all().values() return returnJson.json_responre(title)
def post(self, request): return returnJson.json_responre('success')
def getFile(request, **kwargs): if request.method == 'GET': data = File.objects.all().values() for index, item in enumerate(data): item['video'] = 'media/' + item.get('video') return returnJson.json_responre(data)