我的图像是根据配置文件参数命名的。将信息传递给django模板图像
一个例子是 - 个人资料编号3423
图像将HTTP /路/ imagebig3423.jpg
<img alt="" src="http://path/imagebig[profileid]" />
我如何传递信息给模板?
我的图像是根据配置文件参数命名的。将信息传递给django模板图像
一个例子是 - 个人资料编号3423
图像将HTTP /路/ imagebig3423.jpg
<img alt="" src="http://path/imagebig[profileid]" />
我如何传递信息给模板?
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 }}" />
通常你传递一个哈希模板,你可以把你的模板在
首先,你可能会发现它涵盖getting started with templates教程的价值重新阅读第3部分。再来看一下模板的文档in detail
剪断,会是这样的一个代码:
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})
这听起来真的就像对象层中的设计缺陷一样。您的个人资料没有影像字段是否有原因? – markijbema 2011-05-09 19:41:23
这不是个人资料图片。这是一个基于注册详细信息自动生成的图像。 – Eva611 2011-05-09 19:54:24