'How to pass multiple arguments from one template to another template?
I'm creating a to do list, and on the detail page I have a list of tasks.
And when I click on the delete button on the side of the task, it will bring me to a delete confirmation page.

Question I've been stuck for a long while trying to figure a way to pass in 2 different pks(dailies.pk & task.pk) from the detail page to the delete confirmation page, so that I can click the delete button to delete task(associated with task.pk) or click "back" to return to the previous page(with dailies.pk as a reference). Currently i'm only able to pass in one argument
dailies_detail.html:
<h3>
<p>
{{dailies.date}}
Dailies pk({{dailies.pk}})
<a href="{% url 'task-create' dailies.pk %}">Add task</a>
</p>
{% for todo in dailies.dailytask_set.all %}
<br>
{{todo.task}} {{todo.pk}} <a href="{% url 'task-delete' todo.pk %}"> Delete</a>
{% endfor %}
</h3>
I tried to do {% url 'task-delete' todo.pk dailies.pk %}, that didn't work
URLS:
urlpatterns = [
path('', DailiesListView.as_view(), name='home'),
path('dailies/<int:pk>/', DailiesDetailView.as_view(), name='todo-detail'),
path('dailies/<int:pk>/task-create/', TaskCreate.as_view(), name='task-create'),
path('dailies/<int:pk>/task-delete/', TaskDelete.as_view(), name='task-delete'),
# I kind of wanted to do something like 'dailies/<int:dailies_pk>/task-delete/<task_pk>/'
]
I know that I need to do something with the URL in order to take in both arguments, not quite sure how to go about it.
View:
class TaskDelete(LoginRequiredMixin, DeleteView):
model = DailyTask
template_name = 'task_confirm_delete.html'
context_object_name = 'task'
# has issues, yet to be able to pass in detail pk
def get_success_url(self):
detail_view_id = self.kwargs['pk']
return reverse_lazy('todo-detail', kwargs={'pk': detail_view_id})
#How can I get both pks? currently only getting task.pk
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
# detail_view_id = self.kwargs['pk_detail']
# context['pk_detail'] = detail_view_id
task_id = self.kwargs['pk']
context['pk'] = task_id
return context
I see some similarity to this question, but I'm still confused: link
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

