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 作为搜索引擎。请求由 POST 发出,服务器处理它们并以 JSON 格式回答。为了更快,我需要在开始时加载一个索引文件(使用 manage.py runserver)以及在调用视图时访问它的方法。
有谁知道该怎么做?
提前致谢 !
在进程启动时加载索引文件意味着每次索引文件更改时都必须重新启动进程。你最好运行一个专用进程作为“搜索引擎”,并让你的 Django 应用程序与这个进程通信(提示:你可能需要一个 json 文档数据库,真的)。
但无论如何:要在进程启动时加载索引,最简单的方法是在您的模型文件之一中进行 - 然后您的视图可以从模型文件中导入它。