标签:version mem lse print index 课程设计 rest pre cms
一、系统概要说明
本系统是一个关于新闻中心的系统,系统总体包括头部导航条、底部图片导航、中间主显示区域布局;用户不仅可以注册、登录、注销系统,还可以发布、搜索、点赞、收藏、评论新闻;用户也可以在个人中心中修改密码、头像、上传头像;此外,本系统具有热门文章、推荐文章和文章分类的显示,用户可以根据自己的需要阅读新闻。
二、网站结构设计
三、模块详细设计
四、数据库设计
alembic_version表:
banner表:
board表:
cms_role表:
cms_role_user表:
cms_user表:
comment表:
front_user表:
post表:
五、系统实现的关键算法与数据结构
关键算法与数据结构:
bp = Blueprint("front",__name__) @bp.route(‘/‘) def index(): board_id = request.args.get(‘bd‘, type=int, default=None) banners = BannerModel.query.order_by(BannerModel.priority.desc()).limit(4) # 轮播图的排序优先显示 boards = BoardModel.query.all() page = request.args.get(get_page_parameter(), type=int, default=1) start = (page - 1) * config.PER_PAGE end = start + config.PER_PAGE sort = request.args.get(‘sort‘, type=int, default=1) posts = None pasts = None total = 0 query_obj = None if sort == 1: query_obj = PostModel.query.order_by(PostModel.create_time.desc()) elif sort == 2: query_obj = PostModel.query.order_by(PostModel.create_time.desc()) elif sort == 3: query_obj = PostModel.query.order_by(PostModel.create_time.desc()) elif sort == 4: query_obj = db.session.query(PostModel).outerjoin(CommentModel).group_by(PostModel.id).order_by( func.count(CommentModel.id).desc(), PostModel.create_time.desc()) if board_id: query_obj = query_obj.filter_by(board_id=board_id) posts = query_obj.slice(start, end) total = query_obj.count() else: posts = query_obj.slice(start, end) total = query_obj.count() pagination = Pagination(bs_version=3, page=page, total=total, outer_window=0, inner_window=2) context = { ‘banners‘: banners, ‘boards‘: boards, ‘posts‘: posts, ‘pagination‘: pagination, ‘current_board‘: board_id } return render_template(‘front/front_index.html‘, **context) #详情页 @bp.route(‘/p/<post_id>/‘) def post_detail(post_id): post = PostModel.query.get(post_id) if not post: abort(404) return render_template(‘front/front_pdetail.html‘,post=post) #评论 @bp.route(‘/acomment/‘,methods=[‘POST‘]) @login_required def add_comment(): form=AddCommonPostForm(request.form) if form.validate(): content=form.content.data post_id=form.post_id.data post=PostModel.query.get(post_id) if post: comment=CommentModel(content=content) comment.post=post comment.author=g.front_user db.session.commit() return restful.success() else: return restful.params_error(‘没有这篇帖子‘) else: return restful.params_error(form.get_error()) @bp.route(‘/apost/‘,methods=[‘GET‘,‘POST‘]) @login_required def apost(): if request.method == ‘GET‘: boards = BoardModel.query.all() return render_template(‘front/front_apost.html‘,boards=boards) else: form = AddPostForm(request.form) if form.validate(): title = form.title.data content = form.content.data board_id = form.board_id.data board = BoardModel.query.get(board_id) if not board: return restful.params_error(message=‘没有这个板块!‘) post = PostModel(title=title,content=content) post.board = board post.author=g.front_user db.session.add(post) db.session.commit() return restful.success() else: return restful.params_error(message=form.get_error()) #注册 class SignupView(views.MethodView): def get(self): return_to = request.referrer if return_to and return_to != request.url and safeutils.is_safe_url(return_to): return render_template(‘front/front_signup.html‘,return_to=return_to) else: return render_template(‘front/front_signup.html‘) def post(self): form = SignupForm(request.form) if form.validate(): telephone = form.telephone.data username = form.username.data password = form.password1.data user = FrontUser(telephone=telephone,username=username,password=password) db.session.add(user) db.session.commit() return restful.success() else: print(form.get_error()) return restful.params_error(message=form.get_error()) #登录 class SigninView(views.MethodView): def get(self): return_to = request.referrer if return_to and return_to != request.url and return_to != url_for("front.signup") and safeutils.is_safe_url(return_to): return render_template(‘front/front_signin.html‘,return_to=return_to) else: return render_template(‘front/front_signin.html‘) def post(self): form = SigninForm(request.form) if form.validate(): telephone = form.telephone.data password = form.password.data remember = form.remeber.data user = FrontUser.query.filter_by(telephone=telephone).first() if user and user.check_password(password): session[config.FRONT_USER_ID] = user.id if remember: session.permanent = True return restful.success() else: return restful.params_error(message=‘手机号或密码错误!‘) else: return restful.params_error(message=form.get_error()) bp.add_url_rule(‘/signup/‘,view_func=SignupView.as_view(‘signup‘)) bp.add_url_rule(‘/signin/‘,view_func=SigninView.as_view(‘signin‘))
六、成品展示
登录页面:
注册页面:
首页:
新闻列表:
底部图片导航:
修改密码:
修改、上传头像:
收藏、点赞:
详情页:
评论列表:
个人中心:
标签:version mem lse print index 课程设计 rest pre cms
原文地址:https://www.cnblogs.com/JUNJUNER/p/9186995.html