私は本当に奇妙な問題を抱えています。私のインデックスページは画像を示しています。エラーはありません。コードは次のとおりです。
def index(request):
post = Post.objects.get(id=1)
return render_to_response("index.html", {"post":post}, context_instance=RequestContext(request))
しかし、私の詳細ページには画像が表示されません。ここにコード:
class PostDetailView(DetailView):
context_object_name = "post"
model = Post
template_name = "post_detail.html"
def get(self, request, *args, **kwargs):
self.next = self.request.get_full_path()
return super(PostDetailView, self).get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super(PostDetailView, self).get_context_data(**kwargs)
context["form"] = CommentForm()
context["next"] = self.next
context["object_id"] = context['post'].id
context["comments"] = Comment.objects.filter(
content_type=ContentType.objects.get_for_model(self.model),
object_id=context['post'].id, is_published=True)
return context
私のpost_detail.htmlページ:
{{ post.title }} -----here ok!
{{ post.content }} ------here ok!
<div class="img">
{% if post.image %}
<img src="media/{{post.image_thumb}}" /> -----but here not ok.Why?
{% endif %}
</div>
私のindex.html
{{ post.title }}
{{ post.content }}
<div class="img">
{% if post.image %}
<img src="media/{{post.image_thumb}}" />
{% endif %}
</div>
だから私の問題は何ですか、時間をありがとう。