首页 > 解决方案 > 访问变量到另一个应用程序 django

问题描述

我在 Django 中有两个应用程序

├── search
│   └── views.py
│       
└── preprocessing
    └── views.py

在 search/views.py 中,我有如下代码的数据框:

df = pd.DataFrame()
def scrape(request):
    global df
    items = comments + replies
    df = pd.DataFrame(items, columns=['Comments'])
    return render(request, 'search/scrape.html', context)

而且,我想在第二个应用程序中使用来自 search/views.py 的数据框

预处理/views.py

  from search.views import df

    def index(request):
        print(df)
        context = {
            
        }
        return render(request, 'preprocessing/preprocessing.html')

但问题是我传递给 preprocessing/views.py 的数据框是空的,所以,我怎样才能通过 datframe 中的值也来自 search/views.py thx 寻求帮助

标签: pythondjango

解决方案


推荐阅读