def testGetPost(self): """测试model增查""" test1 = post(content='test2', title='title2') test1.save() list = post.objects.all() print("ctest 11") for i in list: print(i.title) self.assertEqual(True, True)
def create(request): if request.method == 'POST': title = request.POST.get('title') data = request.POST.get('data') date = request.POST.get('date') post_object = post(title=title, data=data, date=date) post_object.save() return render(request, 'form.html', {'message': 'success'}) else: return render(request, 'form.html')
def new_blog(request): if request.method == 'POST': print (request.POST.get('title')) blog = post(title=request.POST.get('title'), body=request.POST.get('body'), user_id=request.session['user_id'] ) blog.save() return redirect('index') else: if 'user_id' in request.session: first_name = request.session['first_name'] return render(request, 'new_blog.html', {'first_name': first_name}) else: return redirect('index')
def add_post(request): if request.method == 'POST': Post = post() Post.title = request.POST.get('title') Post.desc = request.POST.get('content') Post.author = request.POST.get('author') Post.language = request.POST.get('language') Post.category = request.POST.get('category') Post.readtime = request.POST.get('readtime') Post.save() messages.success(request, 'Posted successfully...') return HttpResponseRedirect('/blog') else: return render(request, 'addpost.html')
def Addpost(request): if request.user.is_authenticated: if request.method == 'POST': s = Postform(request.POST) if s.is_valid(): title = s.cleaned_data['title'] desc = s.cleaned_data['desc'] pst = post(title=title, desc=desc) pst.save() s = Postform() else: s = Postform return render(request, 'blog/addpost.html', {'form': s}) else: return HttpResponseRedirect('/blog/login/')