モーダルポップアップウィンドウでメモの詳細を作成しようとしています。
これがモーダル呼び出しアンカー タグです
<a class="fa fa-pencil" data-toggle="modal" href="{% url 'post_detail_view' %}" data-id="{{ todo_item.content }}" data-target="#modal" title="edit item" data-tooltip></a>
views.py の view 関数は次のとおりです。
def post_detail_view(request, content):
all_items1 = TodoItem.objects.get(content=content)
return render(request, 'todo.html', {'all_items1': all_items1})
これが私の urls.py です:
path('post_detail_view/<str:content>/', views.post_detail_view, name='post_detail_view'),
これは todo.html のモーダル コードです
<div class="modal-dialog" role="document">
<div class="modal-content">
<form action="/addTodo/" method="post" enctype="multipart/form-data">
{% csrf_token %}
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabe2">Edit Info</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
{% if all_items1 %}
<label for="content">Title :</label><br>
<p>{{ all_items1.content }}</p>
<p>{{ all_items1.data }}</p>
<input type="text" id='c' name="content" value="{{ all_items1.content }}"/><br>
<label for="data">Description :</label><br>
<textarea id="data" rows="4" cols="50" value="">{{ all_items1.data }}</textarea>
<br>
<label for="tags">Tags :</label><br>
<input type="tags" name="tags" value="{{ all_items1.tags }}"/><br>
<a href="https://stackoverflow.com/questions/63744846/{{ all_items1.file.url }}">
{% load static %}
<img src="https://stackoverflow.com/questions/63744846/{% static 'ico.png' %}" style="width:30px;height:30px" alt="download">
</a>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
{% endif %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</form>
</div>
このコードは機能しません。モーダルがポップアップしているのはわかりますが、データが表示されません。私はまだジャンゴを勉強中です。誰か助けてくれませんか。
------------------------
パラメータがビュー層に渡されていないと思います。これを試してみてください:
<a class="fa fa-pencil" data-toggle="modal" href="{% url 'post_detail_view' todo_item.content %}" data-target="#modal" title="edit item" data-tooltip></a>