def image_create(request): context = dict() if request.method == 'POST': form = ImageCreateForm(data=request.POST) if form.is_valid(): cd = form.cleaned_data new_item = form.save(commit=False) # assign current user to item new_item.user = request.user new_item.save() messages.success(request, 'Your image has been added successfully') # redirect to the item's detail view return redirect(new_item.get_absolute_url()) else: # build form with GET data provided by bookmarklet form = ImageCreateForm(data=request.GET) context['section'] = 'images' context['form'] = form return render(request, 'images/image/create.html', context)
def post(self, request): if request.method == 'POST': form = ImageCreateForm(data=request.POST) if form.is_valid(): cd = form.cleaned_data new_item = form.save(commit=False) # assign current user to the item new_item.user = request.user new_item.save() messages.success(request, 'Image added successfully') # redirect to new created item detail return redirect(new_item.get_absolute_url())
def image_create(request): if request.method == 'POST': form = ImageCreateForm(data=request.POST) if form.is_valid(): try: new_item = form.save(commit=False) new_item.user = request.user new_item.save() return redirect(new_item.get_absolute_url()) except urllib.error.HTTPError: return HttpResponse('Error: %s' % 'Your request URL is forbidden!') else: form = ImageCreateForm(data=request.GET) return render(request, 'images/image/create.html', {'section': 'images', 'form': form})
def image_create(request): if request.method == 'POST': form = ImageCreateForm(data=request.POST) if form.is_valid(): cd = form.cleaned_data new_item = form.save(commit=False) new_item.user = request.user new_item.save() messages.success(request, 'успешно') return redirect(new_item.get_absolute_url()) else: form = ImageCreateForm(data=request.GET) return render(request, 'images/image/create.html', { 'section': 'images', 'form': form })
def image_create(request): if request.method == 'POST': form = ImageCreateForm(data=request.POST) if form.is_valid(): cd = form.cleaned_data # WE USE OUR OWN FUNCTION HERE, that downloads the actual image new_item = form.save(commit=False) new_item.user = request.user new_item.save() messages.success(request, 'Image added successfully') return redirect(new_item.get_absolute_url()) else: form = ImageCreateForm(data=request.GET) return render(request, 'images/image/create.html', {'section': 'images', 'form': form})
def image_create(request): if request.method =='POST': form = ImageCreateForm(request.POST) if form.is_valid(): # 表单验证通过 cd =form.cleaned_data new_item = form.save(commit=False) # 把当前用户附加到数据对象上 new_item.user = request.user new_item.save() messages.success(request,'图片添加成功!') return redirect(new_item.get_absolute_url()) else: form = ImageCreateForm(request.GET) print(form) return render(request,'images/create.html',{'selection':'images','form':form})
def image_create(request): if request.method == "POST": form = ImageCreateForm(data=request.POST) if form.is_valid(): cd = form.cleaned_data new_item = form.save(commit=False) new_item.user = request.user new_item.save() create_action(request.user, 'bookmarked image', new_item) messages.success(request, 'Image added sunccessfully') return redirect(new_item.get_absolute_url()) else: form = ImageCreateForm(data=request.GET) return render(request, 'images/image/create.html', { 'section': 'images', 'form': form })
def image_create(request): if request.method == 'POST': form = ImageCreateForm(data=request.POST) if form.is_valid(): cd = form.cleaned_data new_image = form.save(user=request.user) create_action(request.user, 'bookmarked', new_image) messages.success(request, 'Image added successfully!') return redirect(new_image.get_absolute_url()) else: form = ImageCreateForm(data=request.GET) return render(request, 'images/image/create.html', { 'section': 'images', 'form': form })
def image_create(req): if req.method == 'POST': form = ImageCreateForm(req.POST) if form.is_valid(): cd = form.cleaned_data new_item = form.save(False) new_item.user = req.user new_item.save() create_action(req.user, 'Bookmarked image', new_item) messages.success(req, 'Image berhasil ditambah') return redirect(new_item.get_absolute_url()) else: form = ImageCreateForm(req.GET) cx = { 'section': 'images', 'formKey': form } return render(req, 'images/create.html', cx)
def image_create(request): if request.method == "POST": #表单提交 form = ImageCreateForm(request.POST) if form.is_valid(): #表单通过认证 cd = form.cleaned_data new_image = form.save(commit=False) #将当前用户附加到数据对象上 new_image.user = request.user new_image.save() create_action(request.user, "添加了图片", new_image) messages.success(request, "图片添加成功!") return redirect(reverse("dashboard")) else: form = ImageCreateForm(request.GET) data = { "section": "images", "form": form, } return render(request, "images/create.html", data)
def image_create(request): if request.method == "POST": # 表单被提交 form = ImageCreateForm(request.POST) if form.is_valid(): # 表单验证通过 cd = form.cleaned_data new_item = form.save(commit=False) #吧当前用户附加到数据对象上 new_item.user = request.user new_item.save() # 行为流 添加图片动作 create_action(request.user, '添加了图片', new_item) messages.success(request, '图片添加成功') return redirect(new_item.get_absolute_url()) else: form = ImageCreateForm(request.GET) return render(request, 'images/create.html', { 'section': 'images', 'form': form })
def image_create(request): if request.method == 'POST': # Форма отправлена. form = ImageCreateForm(data=request.POST) if form.is_valid(): # Данные формы валидны. cd = form.cleaned_data new_item = form.save(commit=False) # Добавляем пользователя к созданному объекту. new_item.user = request.user new_item.save() create_action(request.user, 'bookmarked image', new_item) messages.success(request, 'Image added successfully') # Перенаправляем пользователя на страницу сохраненного изображения. return redirect(new_item.get_absolute_url()) else: # Заполняем форму данными из GET-запроса. form = ImageCreateForm(data=request.GET) return render(request, 'images/image/create.html', { 'section': 'images', 'form': form })
def image_create(request): if request.method == 'POST': # form is sent form = ImageCreateForm(data=request.POST) if form.is_valid(): # form data is valid cd = form.cleaned_data new_item = form.save(commit=False) # assign current user to the item new_item.user = request.user new_item.save() messages.success(request, 'Image added successfully') # redirect to new created item detail view return redirect(new_item.get_absolute_url()) else: # build form with data provided by the bookmarklet via GET form = ImageCreateForm(data=request.GET) return render(request, 'images/image/create.html', {'section': 'images', 'form': form})