BBS論壇(二十三)

2021-09-08 14:06:43 字數 4129 閱讀 4068

class

boardmodel(db.model):

__tablename__ = '

board

'id = db.column(db.integer, primary_key=true, autoincrement=true)

name = db.column(db.string(20), nullable=false)

create_time = db.column(db.datetime, default=datetime.now)

(2)manage.py

生成資料庫表

python manage.py db migrate

python manage.py db upgrade

(3)cms/forms.py

class

addboardsform(baseform):

name=stringfield(validators=[inputrequired(message='

請輸入版塊名稱

'),length(2,15,message='

長度應在2-15個字元之間

')])

class

updateboardform(addboardsform):

board_id=integerfield(validators=[inputrequired(message='

請輸入版塊名稱

')])

(4)cms/views.py

@bp.route('

/boards/')

@login_required

@permission_required(cmspermission.boarder)

defboards():

board_models=boardmodel.query.all()

context=

return render_template('

cms/cms_boards.html

',**context)

@bp.route(

'/aboards/

',methods=['

post'])

@login_required

@permission_required(cmspermission.boarder)

defaboards():

form=addboardsform(request.form)

ifform.validate():

name=form.name.data

board=boardmodel(name=name)

db.session.add(board)

db.session.commit()

return

restful.success()

else

:

return restful.params_error(message=form.get_error())

@bp.route(

'/uboards/

',methods=['

post'])

@login_required

@permission_required(cmspermission.boarder)

defuboards():

form=updateboardform(request.form)

ifform.validate():

board_id=form.board_id.data

name=form.name.data

board=boardmodel.query.get(board_id)

ifboard:

board.name=name

db.session.commit()

return

restful.success()

else

:

return restful.params_error(message='

沒有這個版塊')

else

:

return restful.params_error(message=form.get_error())

@bp.route(

'/dboards/

',methods=['

post'])

@login_required

@permission_required(cmspermission.boarder)

defdboards():

board_id=request.form.get('

board_id')

ifnot

board_id:

return restful.params_error(message='

請傳入版塊id')

board=boardmodel.query.get(board_id)

ifboard:

db.session.delete(board)

db.session.commit()

return

restful.success()

else

:

return restful.params_error(message='

沒有這個版塊

')

(5)cms/js/boards.js

$(function

() ,

'success': function

(data)

else

}});}})

});});

(6)cms/cms_boards.html

板塊管理

<

script

src="}"

>

script

>

}<

div

class

="top-box"

>

<

button

class

="btn btn-warning"

id="add_board_btn"

style

="float: right"

>新增新版塊

button

>

div>

<

table

class

="table table-bordered"

>

<

thead

>

<

tr>

<

th>版塊名稱

th>

<

th>帖子數量

th>

<

th>建立時間

th>

<

th>操作

th>

tr>

thead

>

<

tbody

>

<

tr data-name

="}"

data-id

="}"

>

<

td>}

td>

<

td>0

td>

<

td>}

td>

<

td>

<

button

class

="btn btn-default edit-board-btn"

>編輯

button

>

<

button

class

="btn btn-danger delete-board-btn"

>刪除

BBS論壇(二十)

from exts import dbfrom datetime import datetime class bannermodel db.model tablename banner id db.column db.integer,primary key true,autoincrement tr...

隨筆 二十三

1.gradle 完a整指南 android 2.android gradle 外掛程式 3.0 挖坑日記 3.android效能優化全方面解析 4.android studio 3.2新功能特性 5.重新認識 androidstudio 和 gradle,這些都是你應該知道的 6。美團外賣andr...

演算法(二十三)

1 給定乙個整數陣列nums,找到乙個具有最大和的連續子陣列 子陣列最少包含乙個元素 返回其最大和。public int maxsubarray int nums return maxsum 複雜度分析 public int maxsubarray int nums return maxsum 2 ...