Reputation: 11
I'm currently developping a micro_blog to learn Django, and i didn't find the way to make a page only visible by one User.
ex: i want that each user got a private page on /profile/username/private .
How sould i do to make that only the user "username" got access to it?
For the moment, every-user can access to this page by typing the url.
I already put the " @login_required "
on head of my func, but logged user can still access to the page.
Hope that you'll understand my issue,
Kind Regards,
[UPDATE]
I successfully made it by comparing the name of the current connected user with the name of the owner private page. As each username is unique in the DataBase, the way i did it works.
Upvotes: 1
Views: 1196
Reputation: 1216
Create your own decorator that will validate the logged in user before going into the view and show the content accordingly. Put a check in the template that the logged in user is requesting the page. You can use both @login_required and your own decorator on your view.
Upvotes: 2