from flask import render_template, request, redirect, url_for, flash, current_app, jsonify, send_from_directory
from flask_login import login_user, logout_user, login_required, current_user
from . import admin
from app.extensions import db,app_helper
from .forms import AddAdminForm, LoginForm, AddUserForm, DeleteUserForm, EditUserForm, ArticleForm, \
ChangePasswordForm, AddFolderForm, CategoryForm, RecommendForm, InvitcodeForm, OnlineToolForm
from app.models import User, Category, Tag, Article, Recommend, AccessLog, Picture, InvitationCode, \
OnlineTool
import os
from datetime import datetime
from app.util import admin_required, author_required, isAjax, upload_file_qiniu, allowed_file, \
baidu_push_urls, strip_tags, gen_invit_code
from app.settings import config
@admin.route('/', methods=['GET', 'POST'])
@login_required
@admin_required
def index():
current_user.ping()
return render_template('admin/index.html')
@admin.route('/login', methods=['GET', 'POST'])
def login():
login_form = LoginForm(prefix='login')
user = User.query.filter_by(status=True).first()
if not user:
add_admin_form = AddAdminForm(prefix='add_admin')
if add_admin_form.validate_on_submit():
u = User(username=add_admin_form.username.data.strip(),
email=add_admin_form.email.data.strip(),
password=add_admin_form.password.data.strip(),
status=True, role=True
)
db.session.add(u)
db.session.commit()
login_user(user=u)
return redirect(url_for('admin.index'))
return render_template('admin/add_admin.html', addAdminForm=add_admin_form)
else:
if login_form.validate_on_submit():
u = User.query.filter_by(username=login_form.username.data.strip()).first()
if u is None:
flash({'error': '帐号未注册!'})
elif u is not None and u.verify_password(login_form.password.data.strip()) and u.status:
login_user(user=u, remember=login_form.remember_me.data)
return redirect(url_for('admin.index'))
elif not u.status:
flash({'error': '用户已被管理员注销!'})
elif not u.verify_password(login_form.password.data.strip()):
flash({'error': '密码不正确!'})
return render_template('admin/login.html', loginForm=login_form)
@admin.route('/logout')
@login_required
def logout():
"""
退出系统
"""
logout_user()
return redirect(url_for('main.index'))
@admin.route('/articles', methods=['GET'])
@login_required
@admin_required
def articles():
title = request.args.get('title','')
page = request.args.get('page', 1, type=int)
articles = Article.query.filter(
Article.title.like("%" + title + "%") if title is not None else ''
).order_by(Article.timestamp.desc()).paginate(page, per_page=current_app.config['H3BLOG_POST_PER_PAGE'], error_out=False)
return render_template('admin/articles.html', articles=articles,title = title)
@admin.route('/article/edit/<id>', methods=['GET'])
@login_required
@admin_required
def article_edit(id):
article = Article.query.get(int(id))
form = ArticleForm(obj=article)
form.tags.data = ','.join([t.name for t in article.tags.all()])
return render_template('admin/write.html', form=form)
@admin.route('/article/write', methods=['GET','POST'])
@login_required
@admin_required
def write():
form = ArticleForm()
if form.validate_on_submit():
# --------以下功能是增加文章的分类
cty = Category.query.get(int(form.category_id.data))
a = None
if form.id.data:
a = Article.query.get(int(form.id.data))
if a :
a.title = form.title.data.strip()
a.content = form.content.data
a.content_html = a.content_to_html()
a.summary = form.summary.data
a.thumbnail = form.thumbnail.data
a.category = cty
a.name = form.name.data.strip()
a.state = form.state.data
a.timestamp = form.timestamp.data
if not a.name and len(a.name) == 0 :
a.name = a.id
db.session.commit()
else:
# --------以下功能是将文章信息插入数据库
a = Article(title=form.title.data.strip(), content=form.content.data,
thumbnail = form.thumbnail.data,name = form.name.data.strip(),
state = form.state.data,summary = form.summary.data,
category=cty, author=current_user._get_current_object())
a.content_html = a.content_to_html()
db.session.add(a)
db.session.commit()
if not a.name and len(a.name) == 0 :
a.name = a.id
db.session.commit()
# --------以下功能是将文章标识插入数据库
a.tags = []
for tg in form.tags.data.split(','):
if tg.strip() == '':
continue
t = Tag.query.filter_by(name=tg.strip()).first()
if not t:
t = Tag(name=tg.strip())
db.session.add(t)
if t not in a.tags :
a.tags.append(t)
if isAjax() :
msg = '发布成功' if int(form.state.data) == 1 else '保存成功'
return jsonify({'code':1,'msg':msg,'id':a.id})
return render_template('admin/write.html', form=form)
@admin.route('/users', methods=['GET', 'POST'])
@login_required
@admin_required
def users():
add_user_form = AddUserForm(prefix='add_user')
delete_user_form = DeleteUserForm(prefix='delete_user')
if add_user_form.validate_on_submit():
if add_user_form.role.data == 'True':
role = True
else:
role = False
if add_user_form.status.data == 'True':
status = True
else:
status = False
u = User(username=add_user_form.username.data.strip(), email=add_user_form.email.data.strip(),
role=role, status=status, password='123456')
db.session.add(u)
flash({'success': '添加用户<%s>成功!' % add_user_form.username.data.strip()})
if delete_user_form.validate_on_submit():
u = User.query.get_or_404(int(delete_user_form.user_id.data.strip()))
db.session.delete(u)
flash({'success': '删除用户<%s>成功!' % u.username})
users = User.query.all()
return render_template('admin/users.html', users=users, addUserForm=add_user_form,
deleteUserForm=delete_user_form)
@admin.route('/user-edit/<user_id>', methods=['GET', 'POST'])
@login_required
@admin_required
def user_edit(user_id):
user = User.query.get_or_404(user_id)
edit_user_form = EditUserForm(prefix='edit_user', obj=user)
if edit_user_form.validate_on_submit():
user.username = edit_user_form.username.data.strip()
user.email = edit_user_form.email.data.strip()
if edit_user_form.role.data == 'True':
user.role = True
else:
user.role = False
if edit_user_form.status.data == 'True':
user.status = True
else:
user.status = False
flash({'success': '用户资料已修改成功!'})
return render_template('admin/edit_user.html', editUserForm=edit_user_form, user=user)
@admin.route('/password', methods=['GET', 'POST'])
@login_required
@admin_required
def password():
change_password_form = ChangePasswordForm(prefix='change_password')
if change_password_form.validate_on_submit():
if current_user.verify_password(change_password_form.old_password.data.strip()):
current_user.password = change_password_form.password.data.strip()
# db.session.add(current_user)
db.session.commit(
没有合适的资源?快使用搜索试试~ 我知道了~
毕设 Python基于Flask框架个人博客网站设计.zip
共494个文件
js:197个
html:140个
css:62个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 80 浏览量
2023-10-24
11:17:33
上传
评论
收藏 2.62MB ZIP 举报
温馨提示
matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行!
资源推荐
资源详情
资源评论
收起资源包目录
毕设 Python基于Flask框架个人博客网站设计.zip (494个子文件)
AUTHORS 6KB
bootstrap.min.css 156KB
editormd.min.css 60KB
editormd.preview.css 59KB
font-awesome.min.css 30KB
ambiance.css 26KB
layer.css 14KB
blog.css 8KB
codemirror.css 8KB
toastr.min.css 6KB
codemirror.min.css 5KB
layer.css 5KB
mdn-like.css 5KB
solarized.css 5KB
monokai.css 4KB
merge.css 3KB
night.css 3KB
admin.css 3KB
lint.css 3KB
xq-dark.css 3KB
lesser-dark.css 2KB
pastel-on-dark.css 2KB
xq-light.css 2KB
tomorrow-night-eighties.css 2KB
detail.css 2KB
base_comment.css 2KB
erlang-dark.css 2KB
zenburn.css 2KB
twilight.css 2KB
midnight.css 2KB
vibrant-ink.css 2KB
mbo.css 2KB
base16-dark.css 2KB
base16-light.css 2KB
tern.css 2KB
3024-night.css 2KB
paraiso-dark.css 2KB
paraiso-light.css 2KB
tomorrow-night-bright.css 2KB
3024-day.css 2KB
blackboard.css 2KB
colorforth.css 2KB
the-matrix.css 2KB
night.css 2KB
rubyblue.css 2KB
monokai.css 1KB
cobalt.css 1KB
simplescrollbars.css 1KB
account.css 1KB
eclipse.css 1KB
neo.css 932B
elegant.css 768B
login.css 767B
neat.css 693B
show-hint.css 662B
dialog.css 502B
tiki.css 440B
foldgutter.css 435B
tiddlywiki.css 220B
matchesonscrollbar.css 188B
fullscreen.css 116B
ambiance-mobile.css 103B
write.css 0B
fontawesome-webfont.eot 59KB
fontawesome-webfont.eot 59KB
editormd-logo.eot 1KB
editormd-logo.eot 1KB
loading@3x.gif 21KB
loading@2x.gif 16KB
loading.gif 8KB
loading-0.gif 6KB
loading-2.gif 2KB
loading-1.gif 701B
.gitignore 1KB
.gitkeep 0B
.gitkeep 0B
index.html 22KB
index.html 17KB
index.html 13KB
index.html 13KB
index.html 11KB
index.html 10KB
write.html 9KB
index.html 9KB
index.html 8KB
index.html 8KB
index.html 7KB
index.html 6KB
index.html 6KB
index.html 6KB
index.html 6KB
index.html 6KB
index.html 6KB
index.html 5KB
add_admin.html 5KB
about.html 5KB
index.html 5KB
base.html 4KB
index.html 4KB
index.html 4KB
共 494 条
- 1
- 2
- 3
- 4
- 5
资源评论
- htjy1182024-11-04这个资源对我启发很大,受益匪浅,学到了很多,谢谢分享~
天天501
- 粉丝: 616
- 资源: 5906
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 学习记录111111111111111111111111
- JavaScript函数
- java-leetcode题解之Range Sum Query 2D - Mutable.java
- java-leetcode题解之Random Pick Index.java
- java-leetcode题解之Race Car.java
- java-leetcode题解之Profitable Schemes.java
- java-leetcode题解之Product of Array Exclude Itself.java
- java-leetcode题解之Prime Arrangements.java
- MCU51-51单片机
- java-leetcode题解之Power of Two.java
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功