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.
Asked
Active
Viewed 619 times
0
-
https://stackoverflow.com/questions/1116948/django-initialization – Alireza Jul 31 '21 at 06:40
-
This won't work, as at that point the views and URLs are not initialized. So the function won't be able to make request to the route. – Shubh Parmar Jul 31 '21 at 07:23
1 Answers
0
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.

Mhasan502
- 73
- 8