def new_post(request): categories = Category.objects.all() profile = ProfileModel.objects.get(id_user=request.user) if request.method == "POST": text = request.POST.get('text') published_date = timezone.now() id_category = request.POST.get('id_category') id_user = request.user.id image_url = '' if request.FILES: if request.FILES.get('image_url'): url = 'static/image/' + request.FILES.get('image_url').name handle_uploaded_file(request.FILES.get('image_url'), url) image_url = 'image/' + request.FILES.get('image_url').name newPost = Post() newPost.text = text newPost.published_date = published_date newPost.id_category = Category.objects.get(id=id_category) newPost.id_user = User.objects.get(id=id_user) newPost.image_url = image_url newPost.save() profile.count_post += 1 profile.save() return redirect("/profile") return render(request, 'myUser/profile.html', locals())
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash('New post created.', 'success') return redirect(url_for('home')) return render_template('create_post.html', title='New Post', form=form)
def create_post(): form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash('Your post has been created.', category='success') return redirect(url_for('main.home')) return render_template('create_post.html', title='Create Post', form=form)
def NewVisew(request): ''' 新建文章 :param request: 客户端请求头 :return: html页面或者跳转到主页 ''' form = PostForm() title__post = '发布文章' # 按钮名称 if request.method == 'POST': user = User.objects.get(id=request.user.id) if re.match(r'<script>.*?</script>', request.POST.get('content', '')): messages.error(request, '发布文章失败,检测提交js脚本') return redirect('/user/home') post = Post(title=request.POST.get('title', ''), content=request.POST.get('content', ''), user=user, time=datetime.datetime.now()) post.save() t = threading.Thread(target=sendNotify, args=(request, user, post)) t.start() messages.error(request, '发布文章成功,检测提交js脚本') return redirect('/user/home') return render(request, 'post_file.html', locals(), RequestContext(request))
def new_post(): form = Posts() if form.validate_on_submit(): post = Post(title=form.title.data, gender=form.gender.data, Faculty_name=str(form.Faculty_name.data), phone=form.phone.data, interest=form.interest.data, description=form.app_description.data, author=current_user) db.session.add(post) db.session.commit() return redirect(url_for('home')) return render_template('posting.html', form=form, legend='Add Post')
def new_post(): #Instance of the post orm form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash('Your post has been created!', 'success') return redirect(url_for('home')) return render_template('create_post.html', title='New Post', form=form, legend='New Post')