Search code examples
htmldjangodjango-admin-filters

i unable to fetch user information from django admin


i am creating user_edit_profile for that i need to show the details when user filled the details when he was signing up.Show Users all details are stored in django admin but i can't fetch it only i can fetch thing was a username

<div class="form-group">
    <label for="username">Username</label>
    <input type="text" class="form-control" id="username" name="username" value={{user.get_username}}  required>
  </div>

Problem Image below:- https://drive.google.com/file/d/1q_aJYbhYmXj_j7LKKM7_XFTTKUpN7Hpe/view?usp=sharing

i got the username printed in box but with other only printed required so please somebody help to get out from this headache.

edit_profile.html


<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">

    <title>Edit Profile</title>
    <style>
      .form-control {
    display: block;
    width: 66%;
    padding: .375rem .75rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #212529;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #ced4da;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: .25rem;
    transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
}
#left{
    margin-left: -218px;
    width: 36rem;
}
    </style>
  </head>
  <body>

<div class="container">
<div class="col-lg-12 my-4 mx-2">
  <h1>Update Profile</h1>
    <form action= "############" method='POST'>
      <div class="form-group">
        <label for="username">Username</label>
        <input type="text" class="form-control" id="username" name="username" value={{user.get_username}}  required>
      </div>
      <div class="form-group">
        <label for="fname">First Name</label>
        <input type="text" class="form-control" id="fname" name="fname" value={{request.user.get_firstname}}  required>
      </div>
      <div class="form-group">
        <label for="lname">Last Name</label>
        <input type="text" class="form-control" id="lname" name="lname" value={{user.get_lname}}  required>
      </div>
      <div class="form-group">
        <label for="email">Email address</label>
        <input type="email" class="form-control" id="email" name="email" value={{contact.get_Email}}  required>
      </div>
      <!-- <div class="form-group">
        <label for="pass1">Choose a password</label>
        <input type="password" class="form-control" id="pass1" name="pass1" placeholder="Choose Your Password" required>
      </div>
      <div class="form-group">
        <label for="pass2">Confirm Password</label>
        <input type="password" class="form-control" id="pass2" name="pass2" placeholder="Enter your password again" required>
      </div> -->
     
    
            {% csrf_token %}
            <button type="submit" class="btn btn-primary mt-3">Update</button>
    </form>
    <div class="change">
      <h1>Change Your Password</h1>
      <div class="col-lg-12 my-4 mx-2">
      <div class="col-md-12"><label for="pass2">Old Password</label>
        <input type="password" class="form-control" id="pass2" name="pass2" placeholder="Enter your password again" required>
      </div>
      

</div>
</div>
  
<div class="row">
  <div class="col-md-6">
    <label for="pass1">New Password</label>
    <input type="password" class="form-control" id="pass2" name="pass2" placeholder="Enter your password again" required></div>
  <div class="col-md-4" id="left">
    <label for="pass2">Confirm Password</label>
    <input type="password" class="form-control" id="pass2" name="pass2" placeholder="Enter your password again" required></div>
</div>
<button type="submit" class="btn btn-primary mt-3">Update</button>





</div>
 </div>
    <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-U1DAWAznBHeqEIlVSCgzq+c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj" crossorigin="anonymous"></script>

    <!-- Option 2: Separate Popper and Bootstrap JS -->
    <!--
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-eMNCOe7tC1doHpGoWe/6oMVemdAVTMs2xqW4mwXrXsW0L84Iytr2wi5v2QjrP/xp" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-cn7l7gDp0eyniUwwAZgrzD06kc/tftFf19TOAs2zVinnD/C7E91j9yyk5//jjpt/" crossorigin="anonymous"></script>
    -->
  </body>
</html>




    views.py


def handlesignup(request):
    if request.method=='POST':
        username=request.POST['username']
        fname=request.POST['fname']
        lname=request.POST['lname']`enter code here`
        email=request.POST['email']
        pass1=request.POST['pass1']
        pass2=request.POST['pass2']
        myuser=User.objects.create_user(username,fname,email)
        myuser.fname=fname
        myuser.lname=lname
        myuser.email=email
        myuser.save()
        messages.success(request,'Your account has been created {{Users.username}}')
        t.sleep(2)
        return redirect('/')

Solution

  • Finally it's Worked.Thank you all for Helping

    But the Solution Was:

    For User Name---{{ user.get_username }}

    For Email -------{{ user.email}}

    For First name----{{ user.get_full_name }} OR {{user.get_short_name}}

    For Last name-----{{ user.last_name }}