我正在使用 Django 编写我的网站。在编写我的 Python 代码期间,我有许多打印功能。它们都显示在标准控制台中。我想在我的 HTML 代码中的 div 中显示(不刷新页面的实时)我的所有打印,而不仅仅是在控制台中。怎么做?我的代码是:你按下按钮然后 selenium 开始使用 ajax 而不刷新页面,在此期间我想使用 div 在页面上显示进度。
例如,我的代码:
views.py
bot = Instagram()
class InstabotFormView(AjaxFormMixin, FormView):
form_class = LoginInstagramForm
template_name = 'instabot.html'
success_url = 'runinstabot.html'
def form_invalid(self, form):
response = super(InstabotFormView, self).form_invalid(form)
if self.request.is_ajax():
return JsonResponse(form.errors, status=400)
else:
return response
def form_valid(self, form):
response = super(InstabotFormView, self).form_valid(form)
login = form.cleaned_data.get('login')
password = form.cleaned_data.get('password')
tagi = form.cleaned_data.get('tags')
func = form.cleaned_data.get('function')
tags = []
tagi = tagi.split(',')
tags.extend(tagi)
if self.request.is_ajax():
print('It is AJAX')
bot.login(login,password)
bot.search(tags)
if func == '1':
bot.downloadPhoto(tags)
elif func == '2':
bot.doCalculation(tags)
print(tags)
data = {
'message': "Succesfully opened Selenium."
}
return JsonResponse(data)
else:
return response
Instagram()
def downloadPhoto(self):
i = 0
time.sleep(2)
self.driver.find_element_by_xpath('/html/body/span/section/main/div/header/section/ul/li[2]/a').click()
print('Start function downloadPhoto')
print(self.myCurrentList)
for photo in self.myCurrentList:
followerPhoto = self.myCurrentList.index(photo) + 1
print(followerPhoto)
如何在 html div 中显示来自 def downloadPhoto(self) 的所有打印件?
相关分类