Hi, I'm K Om Senapati, a B Tech CSE student at OUTR, Bhubaneswar, and a Pythonista passionate about hackathons, teamwork, and exploring new technologies.
Well actually Jinja really serves its purpose greatly. That being said, it is a templating engine for python.
Jinja is generally static, (HTML rendered before delivery). While JSX is dynamic and is loved by devs mostly for its component-based reusability, nesting and the ability of easily passing props for dynamic behavior.
The best way is to use the best of both worlds.
As in the end, we are converting PyJSX into strings currently for rendering as html, we will be able to use them directly in flask routes. What we can do is break our whole UI into reusable components and then serve them as html when sending via response in flask routes.
A Quick Example for you if my explanation above was messy (sorry 🥲😅😅🥲) -
PyJSX with Flask
With PyJSX, you define your components in Python files (often with a .px extension, though not strictly required for simple cases if transpiled correctly). The output of a PyJSX component is of JSX type which can be formatted in fstrings, which Flask can directly return.
First, define a PyJSX component. You would typically save this in a file, for example, component.px -
Then, in your Flask application (app.py), you would import and use these components:
fromflaskimportFlaskfrompyjsximportauto_setupfromcomponentimportHomePageapp=Flask(__name__)@app.route('/')defhome_pyjsx():# Render the PyJSX component to a string rendered_html=HomePage(user_name="KOmSenpati",items=["Pen","Paper","Laptop"])print(rendered_html)returnf'{rendered_html}',{'Content-Type':'text/html'}if__name__=='__main__':app.run()
With a strong foundation in programming and web development, I possess skills in: - Desktop application development using languages like Java and Python - Full-stack web development using PHP
No, I am even fine with people breaking established industry standards, I get it, it is fun. I just don't like it when people take the joke too seriously and actually start using these in production. Look what happened to React. They invent a new "solution" to the mess they helped create every year, and each solution requires two new inventions.
If you hold your ear from the other side so often that your arms get entangled, you should just let go.
Insightful
Thanks for letting me know. Now build something cool with it
Cool thanks for sharing
You're welcome 🤗. Glad you found it useful 😁.
Insightful
Now build something cool with it
That’s seriously cool ..
Yupp! It is a game changer!
Wow its so cool
But is it better than Jinja2 ?
That can be setup easily with fastapi or flask
Well actually Jinja really serves its purpose greatly. That being said, it is a templating engine for python.
Jinja is generally static, (HTML rendered before delivery). While JSX is dynamic and is loved by devs mostly for its component-based reusability, nesting and the ability of easily passing props for dynamic behavior.
The best way is to use the best of both worlds.
As in the end, we are converting PyJSX into strings currently for rendering as html, we will be able to use them directly in flask routes. What we can do is break our whole UI into reusable components and then serve them as html when sending via response in flask routes.
A Quick Example for you if my explanation above was messy (sorry 🥲😅😅🥲) -
PyJSX with Flask
With PyJSX, you define your components in Python files (often with a .px extension, though not strictly required for simple cases if transpiled correctly). The output of a PyJSX component is of JSX type which can be formatted in fstrings, which Flask can directly return.
First, define a PyJSX component. You would typically save this in a file, for example,
component.px
-Then, in your Flask application (
app.py
), you would import and use these components:See it works perfectly fine -
such a great blog. keep it up
Glad you found it interesting!
Interesting..
Thanks now try it out and let me how it goes
Why, do you hate python?
No, I am even fine with people breaking established industry standards, I get it, it is fun. I just don't like it when people take the joke too seriously and actually start using these in production. Look what happened to React. They invent a new "solution" to the mess they helped create every year, and each solution requires two new inventions.
If you hold your ear from the other side so often that your arms get entangled, you should just let go.
Wow. insightful!
And the HeadWind HTML is super awesome man!! Lol!