我正在练习django,如何在friends_list / followers_list中显示不同的个人资料图片

时间:2019-03-26 10:04:49

标签: django python-3.x django-models django-forms django-templates

我的模板

{% for follow in my_followers %}

 <div class="col s12 m8 offset-m2 l6 offset-l3">
    <div class="card-panel grey lighten-5 z-depth-1">
        <div class="row valign-wrapper">
            <div class="col s2">

                <img src="{{user.appUser_set.all.0.avatar.url}}" alt="" class="circle responsive-img">

                <!-- notice the "circle" class -->
            </div>
            <div class="col s10">
                <span class="black-text">

                    {{follow }} <br>

                </span>
            </div>
        </div>
    </div>
</div>

{% endfor %}

我的观点

def followers(request):

    a = appUsers.objects.get(users=request.user)
    my_followers = a.follow_people.all()

    my_obj = appUsers.objects.all()

    return render(request, 'parsifal_users/followers.html', {'my_followers': my_followers, 'my_obj': my_obj})

我的模特:

class appUsers(models.Model):
    users = models.OneToOneField(User, on_delete=models.CASCADE)
    profile_url = models.URLField()
    location = models.CharField(max_length=100)
    institution = models.CharField(max_length=100)
    avatar = models.ImageField(
        default='default.jpg', upload_to='profile_pics')
    follow_people = models.ManyToManyField(
        User, related_name='followed_by', blank=True)

    def __str__(self):
        return self.users.username

现在我该如何显示此模板中所有关注者的图片有关查询的任何想法或建议?谢谢!!

PS:我是一个初学者,请同时提出一些很好的参考资料和一些好的项目,以便我可以成功地练习django。

0 个答案:

没有答案