class GuestbookView(ArchiveIndexView, CategoryListMixin): model = Guestbook date_field = "posted" template_name = "guestbook.html" paginate_by = 2 allow_empty = True form = None def get(self, request, *args, **kwargs): self.form = GuestbookForm() return super(GuestbookView, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super(GuestbookView, self).get_context_data(**kwargs) context["form"] = self.form return context def post(self, request, *args, **kwargs): self.form = GuestbookForm(request.POST) if self.form.is_valid(): if self.form.cleaned_data["honeypot"] == "": self.form.save() messages.add_message( request, messages.SUCCESS, "Запись успешно добавлена в гостевую книгу") return redirect("guestbook") else: return super(GuestbookView, self).get(request, *args, **kwargs)
class GuestbookView(ArchiveIndexView,CategoryListMixin): model=Guestbook date_field="posted" template_name="guestbook.html" paginate_by=20 allow_empty=True form=None def get(self,request,*args,**kwargs): self.form=GuestbookForm(initial={"user":request.user}) return super(GuestbookView,self).get(request,*args,**kwargs) def get_context_data(self,**kwargs): context=super(GuestbookView,self).get_context_data(**kwargs) context["form"]=self.form return context def post(self,request,*args,**kwargs): self.form=GuestbookForm(request.POST) if self.form.is_valid(): guest=self.form.save(commit=False) guest.user=request.user guest=self.form.save() if request.is_ajax() : return HttpResponse ('!') return super(GuestbookView,self).get(request,*args,**kwargs) return super(GuestbookView,self).get(request,*args,**kwargs)
class GuestbookView(ArchiveIndexView, CategoryListMixin): model = Guestbook date_field = 'posted' template_name = 'guestbook.html' paginate_by = 2 allow_empty = True # False - если список пуст - выведет 404 form = None def get(self, request, *args, **kwargs): self.form = GuestbookForm() return super(GuestbookView, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super(GuestbookView, self).get_context_data(**kwargs) context['form'] = self.form return context def post(self, request, *args, **kwargs): self.form = GuestbookForm(request.POST) if self.form.is_valid(): if self.form.cleaned_data['honeypot'] == '': self.form.save() messages.add_message( request, messages.SUCCESS, 'Запись успешно добавлена в гостевую книгу') return redirect('guestbook') else: return super(GuestbookView, self).get(request, *args, **kwargs)
class GuestbookView(ArchiveIndexView, CategoryListMixin): model = Guestbook date_field = "posted" template_name = "guestbook.html" paginate_by = 12 allow_empty = True form = None def get(self, request, *args, **kwargs): self.form = GuestbookForm() return super(GuestbookView, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super(GuestbookView, self).get_context_data(**kwargs) context["form"] = self.form return context def post(self, request, *args, **kwargs): self.form = GuestbookForm(request.POST) if self.form.is_valid(): if self.form.cleaned_data["honeypot"] == "": self.form.save() messages.add_message(request, messages.SUCCESS, "Запись успешно добавлена в гостевую книгу") return redirect("guestbook") else: return super(GuestbookView, self).get(request, *args, **kwargs)
class GuestbookView(ArchiveIndexView, CaregoryListMixin): model = GuestBook date_field = 'date' template_name = "guestbook.html" paginate_by = 10 allow_empty = True form = None def get(self, request, *args, **kwargs): self.form = GuestbookForm() return super(GuestbookView, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super(GuestbookView, self).get_context_data(**kwargs) context["form"] = self.form return context def post(self, request, *args, **kwargs): self.form = GuestbookForm(request.POST) if self.form.is_valid(): if self.form.cleaned_data['honeypot'] == '': self.form.save() messages.add_message(request, messages.SUCCESS, 'Entry was added in guestbook') return redirect('guestbook') else: return super(GuestbookView, self).get(request, *args, **kwargs)
def post(self, request, *args, **kwargs): self.form = GuestbookForm(request.POST) if self.form.is_valid(): if self.form.cleaned_data["honeypot"] == "": self.form.save() messages.add_message(request, messages.SUCCESS, "Запись успешно добавлена в гостевую книгу") return redirect("guestbook") else: return super(GuestbookView, self).get(request, *args, **kwargs)
def post(self, request, *args, **kwargs): self.form = GuestbookForm(request.POST) if self.form.is_valid(): if self.form.cleaned_data['honeypot'] == '': self.form.save() messages.add_message(request, messages.SUCCESS, 'Запись успешно доваблена в гостевую книгу') return redirect('guestbook') else: return super().get(request, *args, **kwargs)
def post(self, request, *args, **kwargs): self.form = GuestbookForm(request.POST) if self.form.is_valid(): if self.form.cleaned_data['honeypot'] == '': self.form.save() messages.add_message(request, messages.SUCCESS, "Запись успешно добавлена") return redirect('guestbook') else: return super(GuestbookView, self).get(request, *args, **kwargs)
def post(self,request,*args,**kwargs): self.form=GuestbookForm(request.POST) if self.form.is_valid(): guest=self.form.save(commit=False) guest.user=request.user guest=self.form.save() if request.is_ajax() : return HttpResponse ('!') return super(GuestbookView,self).get(request,*args,**kwargs) return super(GuestbookView,self).get(request,*args,**kwargs)
def index(): # 获取所有记录 messages = Message.query.order_by(Message.timestamp.desc()).all() form = GuestbookForm() if form.validate_on_submit(): name = form.name.data content = form.content.data # 实例化Message并创建记录 message = Message(content=content, name=name) db.session.add(message) db.session.commit() flash('留言已提交!') return redirect(url_for('index')) return render_template('index.html', form=form, messages=messages)
def index(request): tpl_vars = {'messages': Message.objects.all()} if request.method == 'POST': form = GuestbookForm(request.POST) if form.is_valid(): form.save() tpl_vars['success_save'] = 1 form = GuestbookForm() else: form = GuestbookForm() tpl_vars['form'] = form return render_to_response('guestbook/index.html', tpl_vars)
def get(self, request, *args, **kwargs): self.form = GuestbookForm() return super(GuestbookView, self).get(request, *args, **kwargs)
def get(self,request,*args,**kwargs): self.form=GuestbookForm(initial={"user":request.user}) return super(GuestbookView,self).get(request,*args,**kwargs)
def get(self, request, *args, **kwargs): self.form = GuestbookForm() return super(GuestbookView, self).get(request, *args, **kwargs) context["form"] = self.form return context