熊猫不导入Excel更改

时间:2018-07-04 08:34:34

标签: python django pandas

我正在一个python / django项目中工作,我在其中从Excel文件中导入了一些数据。

我需要导入的简化视图是:

urls.py

re_path(r'^product_push/', sick_data_views.Products_List_upload, name='product-push')

views.py

def ID_push():
    Products.objects.all().delete()
    df = product.importDataFrameProducts()
    print(df)
    data = Products(
                        ID = str(df['ID'].tolist()).replace("'",'\"'),
    )
    data.save()

def Products_List_upload(request):
    ID_push()
    return HttpResponse(status=204)

models.py

class Products(models.Model):
    ID = models.CharField(max_length=1000000)

lists.py

class product:
    def __init__(self, excel_path = os.path.dirname(os.path.realpath(__file__))+"\\A_Products.xlsx"):
        self.__df =  self.importDataFrameExamplesList(excel_path)

    def importDataFrameExamplesList(self, excel_path):
        # Load json
        df = pd.read_excel(excel_path, keep_default_dates=False)
        return df

    def importDataFrameProducts(self):
        return self.__df

运行服务器时,导入过程将运行,并且我得到正确的输出: 视图调用list.py并更新值。假设:

ID
1
2
3

但是如果我将Excel文件更改为其他值,例如:

ID
4
2
3

如果我运行localhost:8000 / product_push,则导入将返回Excel文件的旧值(1,2,3)。 我不需要自动更新,但是当我运行推入URL时,我应该能够获取更新后的值。 熊猫是否在缓存中存储一​​些变量?因为我只能在重新运行服务器后才能解决此问题。 预先感谢。

0 个答案:

没有答案