实际上,我正在django项目中工作,该项目将输入作为doc(带有段落)文件输入,将其解析为html文件,同时使每个段落都以卡片格式显示。美化整个过程的功能上面有一个@background(schedule = 0)装饰器,因此我无法在该功能内打印任何内容。我想在日志文件中打印已解析的html文件,以检查解析和美化是否正确。有办法吗?
@background(schedule=0)
def background_html_from_zip_with_beautification(file_type, model_id, mail_ids, path_unzipped_dir_root, folder_name, html_file, model_name):
from exam.views import update_feed_for_material
paper = get_model_object(model_name, model_id)
if paper.subject.name in ENGLISH_LANGUAGE_SUBJECTS:
language = 'ENGLISH'
elif paper.subject.name in HINDI_LANGUAGE_SUBJECTS:
language = 'HINDI'
else:
language = str(paper.language)
try:
html_file_path = path_unzipped_dir_root + '/' + folder_name + '/' + html_file
current_directory = path_unzipped_dir_root + '/' + folder_name + '/'
with open(html_file_path, "r", encoding="ISO-8859-1") as wordfile:
modified_html_file_path, message, flag = get_modified_html_file(wordfile, current_directory, model_id, language, model_name)
if flag and modified_html_file_path:
with open(modified_html_file_path, 'r') as html_file:
for line in html_file:
#log statement comes here, i wanted to print line variable in a log file.
with open(modified_html_file_path, "r") as modified_html_file:
s3path, encrypted_s3path, html_s3_url = get_uploaded_files(paper, model_name,
folder_name,modified_html_file, False)
store_s3_urls_of_paper_in_db(s3path, encrypted_s3path, paper, file_type, html_s3_url)
update_feed_for_material(paper, model_name, paper.material_code, paper.is_published)
subject = 'Env: ' + str(ENV) + ' document uploaded for ' + model_name + ' : ' + str(paper.id)
body = 'Questions uploaded successfully.'
else:
subject = 'Env: ' + str(ENV) + 'Error in document uploaded for ' + model_name + ' : ' + str(paper.id)
body = message
print('==========-----------' + str(message))
except:
print('==========-----------' + str(traceback.format_exc()))
subject = 'Env: ' + str(ENV) + ' Error in upload document for '+ model_name + ' : ' + str(paper.id)
body = traceback.format_exc()
send_application_mails(subject, body, mail_ids)