0

이 내 settings.py입니다 :Django - 정적 폴더에 ImageField 개체를 표시 할 수 있습니까?

STATIC_URL = '/static/' 

# Additional locations of static files 
STATICFILES_DIRS = (
    '/home/userName/project/app/static', 
) 

내보기 템플릿에 ImageField 개체를 통과하자. 워드 프로세서 여기에 설명 된대로 그래서 :

https://docs.djangoproject.com/en/1.5/ref/models/fields/#django.db.models.fields.files.FieldFile.url

내 템플릿에

{{ FieldFile.url }} 

를 수행하여 이미지의 URL에 액세스 할 수 있습니다. 그러나 이미지의 URL에 액세스하려고하면 작동하지만 정적으로로드 할 수 있어야합니다. 다음과 같이하고 싶습니다.

{% load staticfiles %} 

<img src="{% static "{{ FieldFile.url }}" %}" alt="" /> 

그러나 작동하지 않습니다. FieldFile.url이

images/imageName.jpg 

가정 해 내가

<img src="{% static "images/imageName.jpg" %}" alt="" /> 

작동

을하지만, 때 어떻게 와서, 어떤 이유로

{{ FieldFile.url }} 

를 사용할 때 작동하지 않습니다?

참고 : 저는 구글 크롬을 사용

{% load staticfiles %} 

<img src="{% static "{{ FieldFile.url }}" %}" alt="" /> 

을하고 '요소 검사'할 때, 당신이 템플릿 태그 안에 이미 있기 때문에이

<img src="/static/%7B%7B%20FieldFile.url%20%7D%7D" alt="" /> 

답변

4

{{ }}이 필요하지 않습니다 보여줍니다 :

<img src="{% static FieldFile.url %}" alt="" /> 
관련 문제