当前位置:网站首页>Flask blog practice - user management

Flask blog practice - user management

2022-06-22 08:31:00 Light programming

Through the functions in the previous sections , We should have been right flask_sqlalchemy I am very familiar with the addition, deletion, modification and query of , Then let's realize The last user management function , User management functions , We mainly show you how to realize flask Image upload function of And user password modification ideas and methods !

Create a user list view

route :app/admin/views.py

@bp.route('/user')
@login_required
def user():
    #  Check out the list of articles 
    page = request.args.get('page', 1, type=int)
    pagination = User.query.order_by(-User.add_date).paginate(page, per_page=10, error_out=False)
    user_list = pagination.items
    return render_template('admin/user.html', user_list=user_list, pagination=pagination)

This view is very simple , We have done the previous chapters many times , There is no need to repeat here !

Create add user view

You should create a form before creating an add view

stay app/admin/forms.py Create a CreateUserForm Form class for

from flask_wtf.file import FileField, FileRequired, FileSize, FileAllowed

class CreateUserForm(FlaskForm):
    #  create form 
    username = StringF
原网站

版权声明
本文为[Light programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220821243720.html