Hi,
I have been looking for the answer since 3 days, so if anyone can make things clearer for me, that would be great (I’m new to Django).
So, i created a CBV with a get method that i supposed to render a template and display a message.
class ShowEntityView(TemplateView):
def get(self, request):
pass
This CBV is accessible through a URL that contains 3 arguments (PID, CHECK, HASH).
path('entities/<entity_pid>/<check_id>/<hash_id>/', ShowEntityView.as_view())
The PID is a unique identifier of a database entity.
As i want to verify the existence of the entity before returning a response, i thought of creating a middleware and calling it using a decorator.
@method_decorator([VerifyExistenceAndSetEntity], name='dispatch')
And the middleware looks something like :
class VerifyExistenceAndSetEntity:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
return HttpResponseNotFound("reached")
# response = self.get_response(request)
# return response
I was expecting to have a 404 page with the message “reached”, but no, i’m having an error :
__call__() got an unexpected keyword argument 'entity_pid'
I tried different approches like using the “MiddlewareMixin” class, but nothing works !
Please tell me what i am doing wrong !
Thank you.