Django テンプレートで画像を取得しようとしています。誰でも助けることができますか?
ここに私のテンプレートコードがあります:
<img src={{myImage}}/>
ここに私のビューコードがあります:
def base_book(request):
theBook = Book.objects.get(title__contains="django")
theAuthors = Book.objects.get(id=2)
myAuthors = theAuthors.authors.all()
myImage = "{{STATIC_URL}}two_scoops_django.png"
return render(request, 'base_book.html', {'book': theBook, 'author': myAuthors, 'myImage': myImage})
次のように、設定のファイルパスの画像ディレクトリに画像ファイル「two_scoops_django.png」を保存しました。
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templatesDir'),
os.path.join(BASE_DIR, 'imageDir'),
)
私はそれを実現しようとしていくつかの異なる組み合わせを試しましたが、まだうまくいきません.
Here is my URL pattern as well if it helps:
# DB - generated URL
url(r'^base_book/$', base_book),
前もって感謝します!