我可以选择从django querysets生成一个html文件。一切工作正常,当点击相应的按钮,它将被重定向到结果页面。现在我需要这样做,生成的文件打开不是在应用程序,而是在谷歌文档。
为此,我使用pydrive
库。根据文档,我为测试创建了文件pydrive.py
和client_secrets.json
pydrive\u gd.py
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
file1 = drive.CreateFile({'title': 'Hello.txt'}) # Create GoogleDriveFile instance with title 'Hello.txt'.
file1.SetContentString('Hello World!') # Set content of the file from given string.
file1.Upload()
这个测试效果很好,在登录到我的Google帐户后,我收到一条消息
Authentication successful.
下一步,我将尝试将pydrive代码连接到django视图。请注意,views.py
、client_secrets.json
、pydrive_gd.py
文件位于同一目录中。
我开始向views.py文件中添加代码,并在添加行gauth.LocalWebserverAuth()
视图.py
#Other import
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()#--->ERROR
我出错了
raise InvalidConfigError('Invalid client secrets file %s' % error)
pydrive.settings.InvalidConfigError: Invalid client secrets file ('Error opening file', 'client_secrets.json', 'No such file or directory', 2)
如果我只是添加到视图中,pyfrom .pydrive_gd import drive
错误是相同的
目前没有回答
相关问题 更多 >
编程相关推荐