user profile in Django

34 weergaven
Naar het eerste ongelezen bericht

Samir Areh

ongelezen,
27 jun 2021, 11:43:4527-06-2021
aan Django users
Hello
I'm new to django. i want to create a user profile. I want to know the best way to do this. thanks 

sum abiut

ongelezen,
27 jun 2021, 17:46:2827-06-2021
aan django...@googlegroups.com
You can use the user model, do something like that
class user_register(models.Model):
      user = models.OneToOneField(User,on_delete=models.CASCADE)
      join_date = models.DateTimeField(default=timezone.now)
To view the user profile, you can do something like this.

def user_profile(request, username):
    user = User.objects.get(username=username)
    context = {
       "user": user
    }


    return render(request, 'profile.html', context)
profile.html

{{user.username}}
{{user.first_name}}


On Mon, Jun 28, 2021 at 2:43 AM Samir Areh <samreho...@gmail.com> wrote:
Hello
I'm new to django. i want to create a user profile. I want to know the best way to do this. thanks 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f84c5af2-12f1-41d3-9002-f0bc96f0371fn%40googlegroups.com.



Abdoulaye Koumaré

ongelezen,
28 jun 2021, 09:17:3228-06-2021
aan Django users
If you're new the best way to create a profile is by using django signals you'll get more information about that at https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html .

Kelvin Sajere

ongelezen,
28 jun 2021, 15:15:1528-06-2021
aan django...@googlegroups.com
I suggest that you use the AbstractUser model that django officially recommends. 

from django.contrib.auth.models AbstractUser

class User(AbstractUser):
    age : models.IntegerField(default=0)
    is_student : models.BooleanField(default=False)
    # extra profile information 

Then also make sure in your settings file you point your auth model to this class

AUTH_USER_MODEL = ‘app_name.User’

This is the safest and easiest way build profiles. You can equally use the AbstractBaseUser model if you need some more flexibility, but for most use case, the AbstractUser model would do.

--
KeLLs
Allen beantwoorden
Auteur beantwoorden
Doorsturen
0 nieuwe berichten