【发布时间】:2021-12-17 02:41:07
【问题描述】:
如何将下面链接的解决方案写入 views.py 以读取多个文件并输出这些不同的字段?我可以做到这一点,但如果我尝试复制粘贴 f = open('path/text.txt', 'r') file_content = f.read() f.close() context = {'file_content': file_content}
稍微改变字母以获得独特的版本,它似乎打破了它......我正在传递独特的变体而不是重复使用“f”例如:h = open(BASE_DIR, 'path/tofile') file_content = h.read () h.close() context = {'file_contenth': file_contenth}
然后我传入return return render(request, pathtohtml, {'file_content': file_content}, {'file_contenth': file_contenth}
这会“破坏”它。我尝试了几种将这些变量传递给但无济于事的变体
我使用了这里找到的解决方案Django: Display contents of txt file on the website
【问题讨论】:
标签: python python-3.x django nginx