djangodjango-modelsdjango-templatesdjango-authenticationdjango-profiles

Profile pages design based on login in Django


I m developing an application that requires a profile page based on user login. May be, this is a repeated question, but I haven't got an Idea about how to do this from other questions on this site.

Problem1: User should have access only to his profile and only upon login.
Problem2: Is there any way by which we can prevent a user from accessing another profile by entering the URL of that profile while he is logged in to his profile
Problem3: Can the urls be made same for every user upon login but the views are based on individual login.
Problem4:What is the best option to save password into a model in Django.

It would be a great help if I get an answer based on class-based views and ObjectMixins

Thanks in advance


Solution

  • The answers to questions 1 to 3 are the same, and that is to simply provide a URL without a parameter - say, /profile/ - which just displays the information from request.user. That way, only logged-in users can see their profiles, and they can only see their own and not anyone else's.

    Question 4 is a bit strange. You should never attempt to write your own code to save passwords. Django does it all for you with the authentication framework. Do not try to rewrite that code unless you really know what you're doing (hint: you don't).