Skip to main content
 首页 » 编程设计

python之在 django 中集成一个外部应用程序,从任何文件夹中获取代码

2025年05月04日29Renyi-Fan

我想安装外部应用 django-disqus在我的博客中。但是,我不想通过 pip install 或 python setup.py install 在系统中安装模块,而是想将代码下载到名为 libs 的特定文件夹,然后将其链接到我的项目。

我的文件夹结构是这样的:

-root_folder 
    -- project (here I have settings.py, urls.py and wsgi.py) 
    -- blog (here I have models.py, admin.py, urls.py, templatetags/, template/) 
    -- libs (here I want to add the code of disqus) 

如果我下载了 libs 中的代码,如何将它链接到 setting.py 中的 INSTALLED_APPS?

注意:我运行的是django 1.8

请您参考如下方法:

您应该能够像注册任何 Django 应用程序一样注册它。

通过添加__init__.py文件使libs成为一个包

然后将其添加到您的设置中。INSTALLED_APPS

INSTALLED_APPS = ( ... 'libs.disqus', )