how to call a function when app start in django?


This Content is from Stack Overflow. Question asked by sourav singha

i want to call the daily_data_log_checker function in that MainConfig class so that it can run when the app start

class MainConfig(AppConfig):
    default_auto_field = 'django.db.models.AutoField'
    name = 'main'

    def daily_data_log_checker():
        import datetime
        from datetime import datetime
        from datetime import date
        from main.models.status import DailyMachinePerformance
        from import log_daily_data
        now_time =
        today =
        if(now_time.hour>= 11):
            daily_machine_performance = DailyMachinePerformance.objects.filter(date = today)
            if(len(daily_machine_performance) == 0):


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?