Home > Net >  im want when user click profile pass to profile.html
im want when user click profile pass to profile.html

Time:01-27

i want to user when click profile pass user to profile.html but problem i don't solve hem

enter image description here

--------- path

path('home', views.home, name="home"),
path('profile/<int:id>', views.profile_views, name="profile_views")

-------- models

class profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    music = models.CharField(max_length=50)
    skils = models.CharField(max_length=50)
    search = models.CharField(max_length=50)
    posts = models.CharField(max_length=50)
    boi = models.TextField()
    img = models.ImageField(upload_to="profile-img")
    def __str__(self):
        #return self.user or 'User'
        return str(self.id) 
def create_profile(sender, **kwargs):
    if kwargs['created']:
        user_profile = profile.objects.create(user=kwargs['instance'])
post_save.connect(create_profile, sender=User)

------- views

def home(request, id):
    pro_id = profile.objects.get(id=id)
    context = {'pro_id' : pro_id}
    return render(request, 'main-frond.html')

def profile_views(request, id):
    ff = profile.objects.get(id=id)
    context = {'ff' : ff}
    return render(request, 'profile.html', context)

------ html

<br>
<a href="{% url 'profile_views' pro_id.id %}">profile</a>
<br>
<hr>
{{request.user}}
<hr>
<a href="{% url 'login' %}" id="login-register" style="float: right;">Login</a>
<a href="{% url 'register' %}" id="login-register">Register</a>

where's the problem

i want to user when click profile pass user to profile.html but problem i don't solve hem

CodePudding user response:

path('home', views.home, name="home"),

does not match

def home(request, id):

CodePudding user response:

If this is your path:

path('home', views.home, name="home"),
path('profile/<int:id>', views.profile_views, name="profile_views")

views.py:

def home(request):
   
    return render(request, 'main-frond.html')
  • Related