我尝试在用户个人资料中创建类似子页面的内容。
我尝试创建它是因为我认为将所有内容(活动流,用户照片,wideo等)放在一个页面中不是一个好主意。
我对一个模型有多种看法,例如:
def userprofile(request, username):
user = User.objects.get(username=username)
context = locals()
template = 'auth/user_detail.html'
feeds = feed_manager.get_user_feed(user.id)
activities = feeds.get('user')['results']
activities = enricher.enrich_activities(activities)
user_from = len(Follow.objects.filter(user_from=user))
target = len(Follow.objects.filter(target=user))
current_user_following = Follow.objects.filter(user_from=request.user, target=user)
args = {"user": user, "target": target,
"current_user_following": current_user_following,
"activities": activities}
return render(request, template, args)
def userabout(request, username):
user = User.objects.get(username=username)
return render(request, 'auth/about.html',
{'user': user})
def userphotos(request, username):
user = User.objects.get(username=username)
return render(request, 'auth/photos.html',
{'user': user})
以及网址:
path('users/<username>/', views.userprofile, name='userdetail'),
path('users/<username>/about/', views.userabout, name='userabout'),
path('users/<username>/photos/', views.userphotos, name='userphotos'),
path('users/<username>/video/', views.uservideo, name='userphotos'),
当我使用诸如localhost:8000 / account / users / Maciej / about /的用户名键入此链接时,这将很好地工作。但是我不知道如何在模板中链接它。
我尝试<a href="{% url 'userabout' %}">About me</a>
,然后出现错误消息“ No reversMatch”。
我是乞gg,也许有更好的选择吗?或链接到此。
答案 0 :(得分:2)
您需要提供用户名作为模板标记的参数。例如:
<a href="{% url 'userabout' user.username %}">About me</a>