title: How to get a field from related object in Django template?
body: <p>I want to have each user's city along with their comments. The <code>city</code> field is defined in UserProfile model. Here are the models:</p>
  
  <pre><code>class UserProfile(models.Model):
      user =  models.OneToOneField(User)
      name = models.CharField(max_length=30, blank=True)
      city = models.CharField(max_length=30, choices= CITY_CHOICES)
  
  
  
  class Comment(models.Model):
      author = models.ForeignKey(User)
      created = models.DateTimeField(auto_now_add=True)
      body = models.TextField()
      post = models.ForeignKey(Dastan)
      published = models.BooleanField(default=True)
  
      def __unicode__(self):
          return unicode("%s: %s" % (self.post, self.body[:60]))
  </code></pre>
  
  <p>The view is:</p>
  
  <pre><code>def post(request, post_id=1):
      post = Article.objects.get(id = post_id)
      comments = Comment.objects.filter(post=post)
      d = dict(post=post, comments=comments, form=CommentForm(), user=request.user)
      d.update(csrf(request))
      return render(request, "article/post.html", d)
  </code></pre>
  
  <p>And in template I have:</p>
  
  <pre><code>{% for comment in comments %}
     &lt;li&gt; {{commnet.author.userprofile.city}} &lt;/li&gt;
     &lt;li&gt; &lt;a href="/profile/{{ comment.author }}"&gt;{{ comment.author }}&lt;/a&gt; &lt;/li&gt;
      &lt;li&gt;&lt;div class="date"&gt; {{ comment.created timesince }}&lt;/div&gt;
  
     &lt;div class="comment_body"&gt;{{ comment.body | linebreaks }}&lt;/div&gt;
  {% endfor %}
  </code></pre>
  
  <p>But the city is not displayed. </p>
  
  <p>So I'm wondering how to access it in the template? </p>