我有4个pdf文件,名称如“第1课,第2课,第3课”等。我希望每个文件在访问每个文件的路径时都呈现。如何将views.py中的变量传递到模板的静态链接中?
我尝试过
{% static 'lectii/lectie-' | add:{lectie}.pdf %}
{% static 'lectii/lectie-{lectie}.pdf %}
没有一个起作用。
这是模板:
{% extends 'base.html' %}
{% load static %}
{% block content %}
</div>
<div id="middle-section" class="container-fluid container-fluid-margin">
<div class="row content-block">
<div class="col-md-12">
<embed src="{% static 'lectii/lectie-{lectie}.pdf %}" style="width: 100%; height: 100vh;"></embed>
</div>
</div>
<div class="row content-block">
<iframe width="100%" height="750" src="https://www.youtube.com/embed/I6dQXpJKlPk" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
</div>
{% endblock %}
views.py
from django.shortcuts import render
from django.shortcuts import get_object_or_404
from .models import Lectie
def lectii(req):
return render(req, '../templates/pagini/lectii-selector.html')
def lectie(req, lectie_id):
lectie2 = get_object_or_404(Lectie, pk=lectie_id)
context = {
'lectie': lectie2
}
return render(req, '../templates/pagini/lectii.html', context)
(lectie =上课)
那么如何将变量包含到该静态路径中? 谢谢。
答案 0 :(得分:1)
最简单的方法是:
src="{% static 'lectii/lectie' %}-{{ lectie }}.pdf"