我正在建立一个具有社会吸引力的网站。
我要显示用户的first_name
和last_name
,用dot(.)
分隔,而不是username
示例:localhost:8000/homepage/profile/john.doe
这是用户个人资料的路径:
path('homepage/profile/<str:username>/', user_view.GetProfile.as_view(), name='user-profile'),
这是视图:
class GetProfile(View):
def get(self, request, username):
user = get_object_or_404(MyModel, username=username)
return render(request, 'profile/profile.html', { 'user': user })
这是模板:
{% extends 'base_test.html' %}
{% block title %} My Site | Profiles {% endblock title %}
{% block content %}
<div class="card-columns text-center padding">
{% for user in mymodel_list %}
<div class="card">
<img class="rounded-circle" style="display:inline-block; vertical-align:middle" src="{{user.profile.image.url}}" width=150 height=150>
<div class="card-body">
<h4 class="card-title">{{user.get_full_name}}</h4>
<p class="card-text">{{user.email}}</p>
<a type="button" href="{% url 'user-profile' user.username %}" style="color:whitesmoke;" class="btn btn-primary btn-sm">Profile</a>
<a type="button" class="btn btn-outline-secondary btn-sm">Connect</a>
</div>
</div>
{% endfor %}
</div>
{% endblock content %}
那可能吗?