2011-05-09 3 views
0

내 이미지의 이름은 프로필 매개 변수에 따라 지정됩니다. 예를 들어이 될 것정보를 장고 템플릿 이미지에 전달

- 프로파일 ID 3423

이미지가

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

어떻게 내가 템플릿에 그 정보를 전달하지 HTTP/경로/imagebig3423.jpg 것입니까? 당신이이 getting started with templates을 커버 튜토리얼의 가치를 다시 읽고 제 3 부 찾을 수 있습니다,

+0

이 정말 소리를 객체 레이어의 디자인 결함처럼. 프로필에 이미지 필드가없는 이유가 있습니까? – markijbema

+0

프로필 사진이 아닙니다. 가입 세부 정보를 기반으로 자동 생성되는 이미지입니다. – Eva611

답변

1

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 }}" /> 
1

당신은 일반적으로 템플릿에 해시를 통과, 당신은 첫째로 그

에서 템플릿을 넣을 수 있습니다. 그런 다음 템플릿 문서를 보면 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})