在视图.py-我希望能够转到一个用户页面,然后单击并从一个按钮跟踪他们,就像twitter一样,我知道如何添加用户,正如您在我的视图中看到的添加变量一样,但我真的不知道如何将其实现为一个按钮,允许我跟踪用户!我已经坚持了一整天,这可能是非常明显的,所以任何帮助都是非常感谢!我不认为我的模板是需要这个问题,但如果它是让我知道!在
@login_required
def home(request, username):
context = {}
if username == request.user.username:
return HttpResponseRedirect('/home /user/{0}'.format(request.user.username))
else:
user = User.objects.get(username=username)
user_profile = UserProfile.objects.filter(user=user)
following = user.userprofile.follows.all()
number = user.userprofile.follows.all().count()
tweet = Tweet.objects.filter(userprofile=user_profile).order_by('date')
yum = Tweet.objects.filter(userprofile=user_profile).count()
add = user.userprofile.follows.add(request.user.userprofile)
context['user'] = user
context['profile'] = user_profile
context['follow'] = following
context['number'] = number
context['tweet'] = tweet
context['yum'] = yum
return render (request, 'homer.html', context)
在模型.py在
^{pr2}$
你可以在一个GET或POST上这样做。这是一个很简单的观点。在
然后在你的网址.py您需要将以下内容添加到urlpatterns中。在
^{pr2}$然后您需要使用一些javascript,如下所示:
这假设一些html如下所示:
相关问题 更多 >
编程相关推荐