Role-based access control
📖 Scenario: You are building a simple web app where users have different roles like 'admin' and 'user'. You want to control which pages each role can see.
🎯 Goal: Create a Flask app that stores user roles, checks the role before showing a page, and only allows admins to see the admin page.
📋 What You'll Learn
Create a dictionary called
users with usernames as keys and roles as valuesCreate a variable called
current_user to simulate the logged-in userWrite a function
check_access(role) that returns true if current_user has the given roleUse
@app.route to create two pages: '/' for all users and '/admin' only for admins💡 Why This Matters
🌍 Real World
Role-based access control is used in websites and apps to show or hide pages based on who is logged in, like admins managing content and users viewing it.
💼 Career
Understanding role-based access control is important for backend developers and web developers to secure parts of applications and manage user permissions.
Progress0 / 4 steps