Flask redirecting multiple routes

前端 未结 4 874
北恋
北恋 2021-01-30 10:49

I\'m trying to implement a redirecting pattern, similar to what StackOverflow does:

@route(\'///\')
@route(\'//\')
de         


        
4条回答
  •  一生所求
    2021-01-30 11:32

    I don't understand why you are redirecting. You don't gain anything with the redirect and as you mentioned yourself, you end up just querying the database multiple times. You don't use the given username in any meaningful way, so just ignore it.

    @route('///')
    @route('//')
    def profile(id, username=None):
        user = User.query.get_or_404(id)
        return render_template('user/profile.html', user=user)
    

    This will satisfy all of your given examples.

提交回复
热议问题