def index(request): if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): Email = strip_tags(request.POST['Email']) Name = strip_tags(request.POST['Name']) Url = strip_tags(request.POST['Url']) Comment = strip_tags(request.POST['Comment']) newComment = Posts(name=Name, email=Email, url=Url, comment=Comment) newComment.save() else: form = CommentForm() posts = Posts.objects.all().order_by("-date") c = {'form': form, 'Posts' : posts} c.update(csrf(request)) return render_to_response('start.html', c)
def post_editing(request): if request.method == "POST": title = request.POST['title'] content = request.POST['content'] if not all([title, content]): return JsonResponse({"code": -1, "info": "请填写标题和内容"}) create_time = int(time.time()) username = request.session.get('username', '') post = Posts(title=title, content=content, create_time=create_time, username=username) post.save() return JsonResponse({"code": 0, "info": ""})
def index(request): if request.method == 'POST': form = CommentForm(request.POST, request.FILES) print form if form.is_valid(): Email = strip_tags(request.POST['Email']) Name = strip_tags(request.POST['Name']) Url = strip_tags(request.POST['Url']) Comment = strip_tags(request.POST['Comment']) Image = form.cleaned_data['Image'] print Image if Image.content_type.split("/")[0] == 'image': newComment = Posts(name=Name, email=Email, url=Url, comment=Comment, image=Image, imageType=Image.content_type) newComment.save() else: form = CommentForm() posts = Posts.objects.all().order_by("-date") c = {'form': form, 'Posts' : posts} c.update(csrf(request)) return render_to_response('start.html', c)
def insert_posts(): cu = cx.cursor() cu.execute( "SELECT head_pic, body_pic, title, body, abstract, tag, timestamp, is_active, id FROM posts ORDER BY id" ) post_items = cu.fetchall() for post in post_items: dt = post[6].split('.') p = Posts(head_pic=str(post[0]), body_pic=str(post[1]), title=post[2], body=post[3], abstract=post[4], tag=post[5], timestamp=datetime.strptime(dt[0], '%Y-%m-%d %H:%M:%S'), is_active=bool(post[7]), post_id=int(post[8])) p.save() else: config_id = ConfigId(post_id=post[8], user_id=1) config_id.save()