How to use jinja2 with IDEA

3 posts / 0 new
Last post
klmi
Offline
Joined: 02/13/2019 - 08:41
How to use jinja2 with IDEA

Did somebody already try to use the template module jinja2 with IDEA? I tried different code examples but don't get any output to html file/browser.

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

I have never played with jinja2 but I have read-up on Django which looks like the same.  I haven't tried doing any integration with IDEA.  Are you trying to pull the information from IDEA and then place it in a browser using jinja2?

klmi
Offline
Joined: 02/13/2019 - 08:41

> Are you trying to pull the information from IDEA and then place it in a browser using jinja2?
Yes that was the idea. I am missing an easy output function from IDEA (10.3). Up to now I am using tkinter messageboxes for smaller messages like in the follwing example:
 
import tkinter
from tkinter import Tk, messagebox
root = Tk()
 
# workaround: hide the Tk root window
root.withdraw()
 
# display error
messagebox.showerror("Error", "ERROR: ...")
root.quit()
 
# display messagebox 
messagebox.showinfo("Messagebox", "Hello World! \n\n Click OK to close window.")
root.destroy()     # root.quit() will also work
 
 
But that's no serious option for longer outputs (f.e. pandas DataFrames).
In such cases I'm redirecting stdout to a textfile:
 
import sys
org_stdout = sys.stdout
f = open("C:\output.txt", "w")
sys.stdout = f
print("hello world")
sys.stdout = org_stdout
f.close()
 
I also tried to redirect the whole console output to a tk text widget but that is not as easy as file output.