【发布时间】:2021-10-10 03:27:26
【问题描述】:
我想在我的个人资料模型中的博客视图页面中添加 profile_pic
models.py
class Profile(models.Model):
user = models.OneToOneField(User,null=True, on_delete=models.CASCADE)
bio = models.TextField()
profile_pic = models.ImageField(null=True, blank=True, upload_to="images/profile/")
class StudentBlogModel(models.Model):
title = models.CharField(max_length=255)
author = models.ForeignKey(User, on_delete=models.CASCADE)
body = RichTextField(blank=True,null=True)
snippet = models.TextField(max_length=255)
Views.py
class BlogView(ListView):
model = StudentBlogModel
template_name = 'blog/home.html'
context_object_name = "StudentBlogModel_list"
paginate_by = 10
home.html
<div class="container">
<div class="row">
<div class="col-lg-8">
<hr>
<div class="profile-feed">
<div class="d-flex align-items-start profile-feed-item">
<img src="{{ }}" alt="profile" class="img-sm rounded-circle mb-5 mx-2">
<div class="ml-4">
<h6>
{% if StudentBlogModel.author.first_name or StudentBlogModel.author.last_name%}
<small class="card-title">{{StudentBlogModel.author.first_name|capfirst}}
{{StudentBlogModel.author.last_name|capfirst}} </small>
{% else %}
<small class="card-title">{{StudentBlogModel.author.username|capfirst}}</small>
{% endif %}
<small class="ml-4 text-muted"><i class="mdi mdi-clock mr-1"></i> {{StudentBlogModel.post_date}}</small>
</h6>
<p>
{{StudentBlogModel.title}}
</p>
在 src 中写什么来获取特定作者的个人资料图片
【问题讨论】:
标签: html django django-models