Django : how to pass event.id/package.id in a template
<p>I have three jobs to be done 
1) Read Packages related to an event 
2) Update Packages related to that event one by one. 
3) Or delete the same package related to that event.
I have my views.py like this : </p>

<pre><code>@login_required 
def update_package(request, pk ):

    package = Packages.objects.get(pk = pk)
    event = AddEvent.objects.get(EventId = package.PackageId)
    if request.method == 'POST': 
        f1 = PackageForm(request.POST, instance = event)
    if f1.is_valid(): 
        f1.save()
        return redirect('update_package' , package , event.id )
    else:
        f1 = PackageForm(instance = event)

    return render(request,'addpackage.html', {'form':f1})

@login_required 
def delete_package(request, pk):
    PackageId = Packages.objects.get(pk=pk)

    if request.method == 'POST' :
        PackageId.delete()
        return redirect('read_package' , PackageId)

    return render(request, 'package_confirm_delete.html',{'object':PackageId})
</code></pre>

<p>And I have my urls.py as</p>

<pre><code>url(r'^update_package/(?P&lt;id&gt;.+)/(?P&lt;pk&gt;.+)$',update_package,name='update_package'),
url(r'^delete_package/(?P&lt;id&gt;.+)/(?P&lt;pk&gt;.+)$', delete_package, name='delete_package'),
</code></pre>

<p>but it gives me an error like this </p>

<pre><code>Reverse for 'update_package' with arguments '(34,)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['organiser/update_package/(?P&lt;id&gt;.+)/(?P&lt;pk&gt;.+)$']
</code></pre>

<p>I am new to all this and I am also not sure if I am doing it right.
To read the package I want the url to be like this </p>

<pre><code>localhost:8000/organiser/read_package/9
</code></pre>

<p>And to update the package 34 in event 9 </p>

<pre><code>localhost:8000/organiser/update_package/9/34
</code></pre>

<p>Please suggest some way out. Any help is really appreciable And thanks in advance. </p>

<p>in My home.html related to models.read_events</p>

<pre><code>{% for event in object_list %}
    &lt;a href="{% url 'read_package' event.id %}" class="btn btn-primary"&gt;Read Packages&lt;/a&gt;
{% endfor %}
</code></pre>

<p>in my Package_home.html related to models.update_package</p>

<pre><code>{% for xyz in object_list %}
    &lt;a href="{% url 'update_package'  xyz.id %}" class="btn btn-primary"&gt;Update&lt;/a&gt;
    &lt;a href="{% url 'delete_package' xyz.id %}" class="btn btn-primary"&gt;delete&lt;/a&gt;
{% endfor %}
</code></pre>

<p>PS : Django version : 1.10</p>

<p>You need to add an <code>id</code> argument to your <code>update_package</code> and <code>delete_package</code> views.</p>

<pre><code>def update_package(request, id, pk):
def delete_package(request, id, pk):
</code></pre>

<p>These arguments must match the ones you have on your urls.</p>

<p>Your <code>delete_package</code> view has errors. You have to redirect to an actual URL, not just the name, you can <a href="https://docs.djangoproject.com/en/1.10/ref/urlresolvers/#reverse" rel="nofollow">use <code>reverse</code> for this</a>. And you can't redirect to a page of a deleted object.</p>

<pre><code>from django.urls import reverse


@login_required 
def delete_package(request, id, pk):
    event = Event.objects.get(id=id)
    package = Package.objects.get(pk=pk)

    if request.method == 'POST':
        package.delete()
        return redirect(reverse('read_package', args=[event.id]))

    return render(request, 'package_confirm_delete.html',{'object':PackageId})
</code></pre>

<p>To use the url in the template use, here's a example:</p>

<pre><code>&lt;a href="{% url read_package package.id %}"&gt;{{ package.name }}&lt;/a&gt;
</code></pre>

python django django-templates django-views