Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
How to wrap custom endpoints in Django Tastypie?

I want to add a dispatch method to some resource so I could use a wrapper decorator on it. The issue is that it only works on the CRUD operations and wont go into the dispatch method on 'original' endpoints:

class SomeResource(SomeBaseResource):
    class Meta(...): ...
    
    def get_something_extra(self, request, **kwargs):
        ...

    def patch_detail(self, request, **kwargs):
        ...

and the base resource:

class SomeBaseResource(ModelResource):
    class Meta(...): ...
    
    # the wrapper
    @decorator_to_wrap_all_methods_with(...)
    def dispatch(self, request_type, request, **kwargs):
         logger.info('Enter')
         response = super(SomeBaseResource, self).dispatch(request_type, request, **kwargs)
         logger.info('Exit')
         return response

So when I use patch request it is working as expected, but wont on calling the get_something_extra api.

How do I wrap ALL methods in resource?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

A workaround solution is to add Middleware:

MIDDLEWARE = (
'my.basic.BaseMiddleware',
...
)

class BaseMiddleware(object):
    def __init__(self, get_response):
        self.get_response = get_response

    @decorator_to_wrap_all_methods_with(...)
    def __call__(self, request):
        response = self.get_response(request)
        return response
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!