我正在创建博客,文章只能通过登录发布。所以我有四个表,例如用户、JSdetails、博客、评论。这四个表是相互关联的。在这里,我想在评论中显示个人资料图片。我试过但无法显示。给我一些想法。我在下面添加了模型、视图、模板...
模型.py
class User(models.Model):
first_name=models.CharField()
last_name=models.CharField()
username=models.CharField()
class JSdetails(models.Model):
user=models.ForeignKey(User)
profilepic=models.ImageField(upload_to='Image')
class Blog(models.Model):
user=models.ForeignKey(User)
btitle=models.CharField()
bcontent=models.TextField(blank=True)
bposted=models.DateTimeField(auto_now = True)
class BComments(models.Model):
user=models.ForeignKey(User)
blog=models.ForeignKey(Blog)
comments=models.TextField()
commentpost=models.DateTimeField(auto_now = True)
视图.py
def blogArticle(request):
articleid=1
article=Blog.objects.filter(id=articleid)
com=BComments.objects.filter(blog_id=articleid)
return render_to_response('registration/BlogArticle.html',{'article':article,'com':com},context_instance=RequestContext(request))
模板
/* Here Article will display */
{% for article in article %}
<h2>{{article.btitle}}</h2>
<p style="text-align:justify;">{{article.bcontent}}</p>
{% endfor %}
/* Here Comments get displayed which is posted by user */
{% for com in com %}
<img style="width:50px;height:50px;" src="Here I need to Display Profile picture" >
<span>{{com.user.username}}</span>
<p style="word-wrap:break-word;">
{{com.comments}}
</p>
{% endfor %}