Starting from a Class based update view (Header table). I call a Class based List View to display all the details lines created (Lines table) for my Header. I have created a GLOBAL val that contains the key value of my Header. Everything was working fine since I tried to insert a button to go back to my Header. The URL works perfectly if I hardcode the key value of my Header. If I try to insert my Global variable it doesn't work. I tried with val(), pk=val, pk=val() but the url doesn't work. It seems that the variable is empty... Most of the time test crash with Error message saying that Reverse for 'headfttlog_update' with keyword arguments '{'pk': ''}' not found. Could someone help me? Thanks in advance.
Urls.py:
urlpatterns = [
re_path(r'^headfttlog/update/(?P<pk>[-\w0-9_@]+)/$',
HeadfttlogUpdateView.as_view(), name='headfttlog_update'),
]
Views.py: in DEBUG I'm printing the val and the content is OK!
class DeafttlogListView(LoginRequiredMixin, PermissionRequiredMixin,
ListView):
permission_required = 'fttlapp.view_deafttlog'
model = Deafttlog
paginate_by = 10
def get_queryset(self):
queryset = Deafttlog.objects.filter(dea_fttlcode=val())
print('Uscita Queryset Lista Deafttlog' )
print(val())
return queryset
html:
<a class="btn btn-outline-info" href="{% url 'headfttlog_update' val %}"
>Back to FTTL header</a>