Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在 django 服务器启动后运行一个函数。现在,该函数应该在所有视图和 URL 都初始化后运行,因为该函数可能会向已注册的路由之一发出请求。
假设您想scrape()从task.py.
scrape()
task.py
您可以像这样调用函数urls.py:
urls.py
from django.urls import path from .task import scrape urlpatterns = [ ... ] scrape()
如果遇到任何问题,您也可以在此处使用线程。