开发者

passing info to django template images

My images are named according to a profile parameter.

an example would be - profile id 3423

the image would be http/path/imagebig3423.jpg

<img alt="" src="http://path/imagebig[profileid]" />

how do i pa开发者_如何转开发ss that info to the template?


views.py:

def some_view(request):
    # get the desire profile_id to pass to the template or set explicitly
    profile_id='3423'
    context = { 'profile_id':profile_id, }
    return render_to_response('some_template.html', context, context_instance=RequestContext(request))

some_template.html:

<img alt="" src="http://path/imagebig{{ profile_id }}" />


You normally pass a hash to the template, and you could put your template in that

Firstly, you might find it worth re-reading part 3 of the tutorial where it covers getting started with templates. Then look at the template docs in detail

A code snipped would be something like:

from django.shortcuts import render_to_response, get_object_or_404
def detail(request, profile_id):
   p = get_object_or_404(Profile, pk=profile_id)
   return render_to_response('profile/detail.html', {'profile': p})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜