【发布时间】:2020-11-19 14:13:38
【问题描述】:
我想实现一个功能,让另一个用户 A 点击另一个用户 B 的图片并自动重定向到用户 B 的个人资料。我该怎么做?请查看我的 HTML,我在其中说明了有关链接的内容
view.py
class profile(models.Model):
user = models.OneToOneField(User, on_delete = models.CASCADE)
bio = models.TextField(blank=True)
def __str__(self):
return f'{self.user.username} profile'
html:
{% for post in posts %}
<div class="icl-NavigationList-item">
<div class="icl-NavigationList-link icl-NavigationList--primary">
<div class="icl-NavigationList-text">
<h2 class="icl-NavigationList-title">
<div class="upperText">
<h2 class="card-title"style="background-color:{{post.post_colours}};">{{post.job_title}}</h2>
<a class="a-tags" href="*{{ i need to link the post author's profile here}}*" data-tippy-content="@dribble_handle">
<img src="{{post.author.profile.profile_pic.url}}" style="border-radius: 100%;float:right;"
alt="author"width="30" height="30"></a></div>
<div class="lowerText"> <p class="card-text">{{post.currency}} {{post.salary}}</p>
<p class="card-text"> Posted on {{post.date_posted}} by {{post.author}} </p>
<br>
{% if user.is_authenticated %}
我的模特
class profile(models.Model):
user = models.OneToOneField(User, on_delete = models.CASCADE)
bio = models.TextField(blank=True)
category = models.CharField(max_length= 1000, choices =
Select_category,default='other')
def get(self, request, *args, **kwargs):
username = self.kwargs['username']
user_profile = profile.objects.get(user__username=username)
gigs = Gig.objects.filter(user__username=username, status=True)
print(user_profile.values())
return render(request, 'blog/profile.html', {'user_profile': user_profile, 'gigs': gigs,'name': username})
【问题讨论】:
-
你的问题是......?到目前为止,您已经给出了代码并说出了您想要的,但您还没有解释该代码的输出有什么问题
-
我该怎么做?
-
去看看什么?就像我编辑了我的评论一样——你有一些关于你想要什么的声明和一堆代码。如果您只是询问如何实现某些东西,那么代码将是无用的分心,我会投票关闭它,因为需要更多细节。 碰巧,您的代码看起来很合理,但我仍然不知道您遇到了什么问题
-
我想知道如何让一个用户查看另一个用户的个人资料先生.. 我不知道如何做到这一点
-
没有。绝对不。你可以用edit 来解释你的问题。我不是个人帮助台