Как перечислить несколько загруженных файлов в шаблоне html
Я успешно создал форму, которая принимает и загружает несколько файлов. Когда я проверяю request.FILES, я вижу, что там перечислены следующие файлы.
<MultiValueDict: {'files': [<InMemoryUploadedFile: example.txt (text/plain)>, <InMemoryUploadedFile: test.txt (text/plain)>]}>
Я хочу перечислить урлы этих файлов в моем html шаблоне, но я не могу заставить их отображаться.
views.py
def CreateNewPost(request,cluster_code):
form = PostForm()
if request.method == 'POST':
form = PostForm(request.POST,request.FILES)
if form.is_valid():
add_cluster_code_to_form = form.save(commit=False)
add_cluster_code_to_form.cluster_code = Cluster.objects.get(cluster_code=cluster_code)
add_cluster_code_to_form.save()
return redirect('view-post',cluster_code)
context = {'form':form}
return render(request,'new-post.html',context)
view-post.html
{% extends 'base.html' %}
{% block content %}
{{cluster_code.cluster_code}} Test <a href="{% url 'new-post' cluster_code.cluster_code %}">Add New Post</a>
{% for post in posts %}
<hr>
<p>{{ post.name }} {{ post.time }}</p>
<p>{{ post.cluster_log | linebreaks }}</p>
{% if post.files %}
{% for file in post.files %}
<p>{{ file.name }}</p>
{% endfor %}
{% endif %}
{% endfor %}
{% endblock content %}
Любой совет будет признателен