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

Question:

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)
Asked By: Gurleen Kaur

||

Answers:

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

Answered By: Lucas Grugru
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.