G '0wly' W
G '0wly' W

Reputation: 11

Django - Make private page by user

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

Answers (1)

binu.py
binu.py

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

Related Questions