I need to add a button to display the information in the template.

my code is:

models.py

class Worker (models.Model): name = models.CharField ('Name', max_length=30) surname = models.CharField ('Surname', max_length=30) class Salary (models.Model): worker = models.ForeignKey(Worker) salary_uah = models.IntegerField ('Salary', max_length=5) 

urls.py

 urlpatterns = [ url(r'^$',home, name='home'), url(r'^add/$',add_worker, name='add'), url(r'^act/$',acts, name='act') 

views.py

 def acts (request, id): if not request.user.is_authenticated(): return redirect('/admin/') worker = get_object_or_404(Worker, id=id) return render(request, 'zpapp/act.html', worker) 

admin.py

 @admin.register(Salary) class SalaryAdmin (admin.ModelAdmin): list_display = ('worker', 'salary_uah', 'button') search_fields = ('worker', 'salary_uah') list_filter = ('worker', 'salary_uah') def button(self, obj): return '<a class="button" href="{}">Print</a>'.format(reverse('admin:zpapp_salary_act', args=[obj.id])) button.short_description = 'Actions' button.allow_tags = True 

When I run the code, I get the error:

NoReverseMatch at /admin/zpapp/salary/ Reverse for 'zpapp_salary_act' with arguments '(2,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []

    1 answer 1

    The problem is that you do not correctly specify the url address for the page in the admin panel. If you need to go to the object page, use the following address:

     reverse('admin:{{ app_name }}_{{ model_name }}_change', args=(object.id,)) 

    Full description of admin URLs