def message(request): count_pv(request) message_list = Message.objects.order_by('-timestamp') form = MessageForm() if request.POST and (request.POST.get('body', '') != ''): if request.session.get('has_msged', False): return HttpResponse("十分钟内只能评论一条哦") ''' if form.is_valid():#验证数据是否合法 name = form.cleaned_data['name'] email = form.cleaned_data['email'] ''' body = request.POST.get('body', '匿') color = request.POST.get('color', '#242424') pos = request.POST.get('pos', '200px|300px') Message.objects.create(name='', email='', body=body, color=color, pos=pos, siteurl='') ''' siteurl = form.cleaned_data['siteurl'] Message.objects.create(name=name,email=email,body=body,siteurl=siteurl) form = MessageForm() ''' request.session['has_msged'] = True return render( request, 'message.html', { 'form': form, 'message_list': message_list.reverse(), 'online': get_online() })
def message(request): mess = {} mess['mess'] = Message.objects.all() if request.method == 'POST': form = MessageForm(request.POST) if form.is_valid(): newmessage = Message( author=request.user, body=form.cleaned_data['body'], ) newmessage.save() return render(request, 'blog/message.html', mess) else: form = MessageForm() mess['form'] = form return render(request, 'blog/message.html', mess)
def user(username): user = User.query.filter_by(username=username).first_or_404() if current_user == user: return render_template("user.html", user=user) else: form = MessageForm() messages = current_user.messages_sent.\ order_by(Message.timestamp.desc()).\ filter_by(recipent_id=user.id) if form.validate_on_submit(): message = Message(sender_id=current_user.id, recipent_id=user.id, body=form.message.data) db.session.add(message) db.session.commit() return render_template("user.html", user=user, form=form, messages=messages)
def message(request): message_list = Message.objects.order_by('-timestamp') form = MessageForm() if request.method == 'POST': form = MessageForm(request.POST) if form.is_valid():#验证数据是否合法 name = form.cleaned_data['name'] email = form.cleaned_data['email'] body = form.cleaned_data['body'] siteurl = form.cleaned_data['siteurl'] Message.objects.create(name=name,email=email,body=body,siteurl=siteurl) form = MessageForm() return render(request,'message.html',{'form': form,'message_list': message_list})
def saveMessage(request): if request.method == 'POST': form = MessageForm(request.POST) if form.is_valid(): new_message = form.save() messages.add_message(request, messages.INFO, "Message added successfully!") return HttpResponseRedirect(reverse('blog:index')) else: form = MessageForm() return render(request, 'blog/new-message.html', {'form', form})
def newMessage(request): form = MessageForm() return render(request, 'blog/new-message.html', {'form': form})
def post(self, request): form = FormMessage(request.POST) if form.is_valid(): ModelMessage.objects.create(subject=form.cleaned_data["subject"], name=form.cleaned_data["name"], email=form.cleaned_data["email"], content=form.cleaned_data["content"]) return render(request, 'blog/contacts.html', {'error': form.errors})