コード例 #1
0
ファイル: views.py プロジェクト: abhinavanand500/Bloggify
def adminside(request):
    user=request.user
    if(user.is_superuser):
        if(request.method=='POST'):
            title=request.POST['title']
            author= request.POST['author']
            slug=request.POST['slug']
            content=request.POST['content']
            post = Post(title=title,author=author,slug=slug,content=content)
            post.save()
            messages.success(request,"Your Post is Published Successfully.")
            return redirect('home')            
        return render(request,'mysite/writing.html')
    else:
        messages.error(request, "You are not authorised to visit this page")
        return redirect('home')
コード例 #2
0
ファイル: views.py プロジェクト: tubacoopa/Old_Django_Site
def post(request):
	form = ImageUploadForm(request.POST, request.FILES)
	username = request.user.username
	if form.is_valid():
		photo = form.cleaned_data['photo']
	else:
		photo = 'empty'
	text = request.POST.get('text', 'empty')
	expiration = request.POST.get('expiration', 'empty')
	post = Post(username=username, photo=photo, text=text, expiration=expiration)
	try:
		post.save()
	except(DataError):
		return render(request, 'post.html', {
            'error_message': "Posts must be 400 characters or less!"})
	else:
		return HttpResponseRedirect(reverse('index'))
コード例 #3
0
def post():
    form = Postform()
    if form.validate_on_submit():
        p_post = Post(title=form.title.data,
                      post=form.content.data,
                      author=current_user)
        db.session.add(p_post)
        db.session.commit()
        flash("ur post has been created ", "success")
        return redirect(url_for('home'))

    return render_template("post.html", title="New Post", form=form)
コード例 #4
0
ファイル: models.py プロジェクト: DaQingTea/myblog
    def content_html(self):
        from mysite.models import Post
        from comment.models import Comment

        result = ''
        if self.display_type == self.DISPLAY_HTML:
            result = self.content
        elif self.display_type == self.DISPLAY_LATEST:
            context = {'posts': Post.latest_posts()}
            result = render_to_string('config/block/sidebar_posts.html',
                                      context)
        elif self.display_type == self.DISPLAY_HOT:
            context = {'posts': Post.hot_posts()}
            result = render_to_string('config/block/sidebar_posts.html',
                                      context)
        elif self.display_type == self.DISPLAY_COMMENT:
            context = {
                'comments':
                Comment.objects.filter(status=Comment.STATUS_NORMAL)
            }
            result = render_to_string('config/block/sidebar_posts.html',
                                      context)
        return result
コード例 #5
0
ファイル: routes.py プロジェクト: PaulcPaul/flask-blog
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('O seu post foi criado!', 'success')
        return redirect(url_for('home'))
    return render_template('create_post.html',
                           title='New Post',
                           form=form,
                           legend='New Post')
コード例 #6
0
def posts():
    page = request.args.get('page', 1, type=int)
    p_posts = Post.query.order_by(Post.date.desc()).paginate(page=page,
                                                             per_page=2)
    form = Postform()
    if form.validate_on_submit():
        p_post = Post(title=form.title.data,
                      post=form.content.data,
                      author=current_user)
        db.session.add(p_post)
        db.session.commit()
        flash("ur post has been created ", "success")
        return redirect(url_for('posts'))
    return render_template('posts.html', posts=p_posts, form=form)
コード例 #7
0
ファイル: adddata.py プロジェクト: Peggy-Dong/20210504
import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'datacenter.settings')
django.setup()

from mysite.models import Post

for i in range(10):
    newdata = Post(title="我的標題{}".format(i + 3), body="我的內文{}".format(i + 3))
    newdata.save()
コード例 #8
0
ファイル: adddata.py プロジェクト: wayder1205/way0324
import csv
import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'datacenter.settings')
django.setup()

from mysite.models import Post

with open("recycle1.csv", newline="\n", encoding="utf-8") as csvfile:
	rows = csv.reader(csvfile, delimiter=",")
	for row in rows:
		print(row)
		newdata = Post(title =str(row[1]),body =str(row[2]))
		newdata.save()