Run a function after django server has started

779 Views Asked by At

I want to run a function after django server has started. Now, that function should run after all the views and URLs are initialized because the function might make requests to one of the registered routes.

1

There are 1 best solutions below

0
Mhasan502 On

Let's assume you want to call scrape() function from task.py.

You can call the function in urls.py like this:

from django.urls import path
from .task import scrape

urlpatterns = [
    ...
]

scrape()

You can also use threading here if you encounter any problem.