def post_view(request): user = check_user(request) if user == None: return redirect('/login/') elif request.method == 'GET': post_form = PostForm() return render(request, 'post.html', {'post_form': post_form}) elif request.method == "POST": form = PostForm(request.POST, request.FILES) if form.is_valid(): image = form.cleaned_data.get('image') caption = form.cleaned_data.get('caption') post = PostModel(user=user, image=image, caption=caption) post.save() client = ImgurClient('f9dc99672fce970','adac0c019ab6a9a2114e85c9c2e7829eb38a8b5d') path = str(BASE_DIR + "\\" + post.image.url) post.image_url = client.upload_from_path(path,anon=True)['link'] post.save() # app = ClarifaiApp() # app.tag_urls(urls=['https://samples.clarifai.com/wedding.jpg'], model='food-items-v1.0') return redirect("/feed/") else: return HttpResponse("Form data is not valid.") else: return HttpResponse("Invalid request.")
def post_view(request): user = check_validation(request) form = PostForm() if user: if request.method == 'GET': form = PostForm() return render(request, 'post.html', {'form': form}) elif request.method == 'POST': form = PostForm(request.POST, request.FILES) if form.is_valid(): image = form.cleaned_data.get('image') caption = form.cleaned_data.get('caption') userpost = PostModel(user=user, image=image, caption=caption) userpost.save() print userpost.image.url path = os.path.join(BASE_DIR, userpost.image.url) print BASE_DIR print path client = ImgurClient( '4e7e0f86b1ec9cd', '826ae58b2d75e41570e839f954b5ff3de73c4514') userpost.image_url = client.upload_from_path(path, anon=True)['link'] userpost.save() return redirect('/feed/') else: form = PostForm() return render(request, 'post.html', {'form': form}) else: return redirect('/login/')
def post_view(request): user = check_validation(request) if user: if request.method == 'POST': form = PostForm(request.POST, request.FILES) if form.is_valid(): image = form.cleaned_data.get('image') caption = form.cleaned_data.get('caption') post = PostModel(user=user, image=image, caption=caption) post.save() path = str(BASE_DIR + "\\" + post.image.url) client = ImgurClient('694830d95a588bb', 'feee9bb6fba57a1a46a668c4c102fd2dd64a1a38') post.image_url = client.upload_from_path(path,anon=True)['link'] post.save() return redirect('/feed/') else: form = PostForm() return render(request, 'post.html', {'form' : form}) else: return redirect('/login/')
def post_view(request): #-----------------------------------------here is the function logic------------------------------------------------------------ user = check_validation(request) if user: if request.method == 'POST': form = PostForm(request.POST, request.FILES) if form.is_valid(): image = form.cleaned_data.get('image') caption = form.cleaned_data.get('caption') post = PostModel(user=user, image=image, caption=caption) post.save() path = str(BASE_DIR+"//"+post.image.url) client = ImgurClient('d2d18027cc82a9e', '455ca114d7df83fad4fae1091316dfab42087c18') post.image_url = client.upload_from_path(path,anon=True)['link'] post.save() return redirect('/feed/') else: form = PostForm() return render(request, 'post.html', {'form' : form}) else: return redirect('/login/')
def post_view(request): user = check_user(request) if user == None: return redirect('/login') elif request.method == 'GET': post_form=PostForm() return render(request,'feed.html',{'post_form':post_form}) elif request.method == "POST": form =PostForm(request.POST,request.FILES) if form.is_valid(): image = form.cleaned_data.get('image') caption = form.cleaned_data.get('caption') post = PostModel(user=user, image=image, caption=caption) post.save() #saving image, caption client = ImgurClient('a6ef522b68f01a9','7d31b3b76ad618f8e97f8951ed87b25b5f87572b') path = str(BASE_DIR) + '\\' + str(post.image) post.image_url = client.upload_from_path(path,anon=True)['link'] post.save() #saving url return redirect('/feed')
def post_view(request): user = check_user(request) if user == None: return redirect('/login/') elif request.method == 'GET': post_form = PostForm() return render(request, 'post.html', {'post_form': post_form}) elif request.method == "POST": form = PostForm(request.POST, request.FILES) if form.is_valid(): image = form.cleaned_data.get('image') caption = form.cleaned_data.get('caption') post = PostModel(user=user, image=image, caption=caption) post.save() client = ImgurClient('005535c6f80c2dc', '2520684355b7cf9e0941c6d82bcf392af1807084') path = str(BASE_DIR + "\\" + post.image.url) post.image_url = client.upload_from_path(path,anon=True)['link'] post.save() return redirect("/feed/") else: return HttpResponse("Form data is not valid.") else: return HttpResponse("Invalid request.")