Can I give parameters to AppConfig.ready() of django?

60 Views Asked by At

I want to get request.user.id as I have to pass it to scheduler in AppConfig.ready() but it gave an error. How can I do it ?

My code is as follows:

class ApiConfig(AppConfig):
    name = 'myapp'

    def ready(self, request):
        print('Here starting scheduler')
        
        from . import msgScheduler
        user_id = request.user.id

        msgScheduler.start(self,request, user_id)
1

There are 1 best solutions below

4
Lucas Grugru On BEST ANSWER

ready function is not called by HttpRequest, so you cannot get any request or authenticated user...

You have to start your scheduler without a request/user or run the start function from a view