Reputation: 1363
I have a flask app with multiple blurprints. They are auth,admin,user,sample,data
.
While registering blueprints I added url_prefix for admin
blueprint. But I like to keep the url prefix as admin
even if the user(admin user) is accessing any views other than auth
also to keep user
as url prefix for all views accessed by ordinary user ,other than for auth
.
@admin.route('/dashboard')
def index():
return render_template('dashboard.html')
this will give me : localip:5000/admin/dashboard
But I need to have localip:5000/admin/sample
even if I am accessing view of a different blueprint.
@admin.route('/sample')
def samples():
return redirect(url_for('sample.index'))
@sample.route('/sample')
def index():
return render_template('sample.html')
Now I am getting localip:5000/sample
But I need localip:5000/admin/sample
or localip:5000/user/sample
based on user role.
Upvotes: 0
Views: 878
Reputation: 167
Have you tried passed the user role in as a url parameter like they show here it seems like you should be able to send what the role is of the current user along with whatever requests you send.
@blueprint.route('/<user_role>/dashboard')
def dashboard(user_role):
return render_template('dashboard.html')
when you redirect to another page just always pass in the user role with it
Upvotes: 1