4 ms·
I love me some Python/Jinja/Flask/CherryPy, but after having written JS apps in React that run seamlessly on the client and the server, I can't imagine going ba
by bsimpson 12y ago
I love me some Python/Jinja/Flask/CherryPy, but after having written JS apps in React that run seamlessly on the client and the server, I can't imagine going back to something like this. The best case scenario, you have to maintain a JS port of your app to support rendering your Jinja templates on the client. Or, you can just use Node, Webpack, and React to serve a single codebase that renders on either end. Save Python for your data API.
- Skywing 12y agoI've never worked on a larger javascript project, so I'm not sure why you'd care if your front-end js renders on the server (i'm assuming this means no visual browser). Is this for purposes of automated testing?
- bsimpson 12y agoIt gives you the best of both worlds: Non-JavaScript user agents, like search bots and scrapers, can still understand your page (as if it's rendered on the server), but you don't need to send redundant markup on each page view (because the client can render the new page with just a diff).
- bsimpson 12y agoIf Nunjucks rendered performantly (like React), I could see the argument being made that it's the same upsides with an easier to read syntax (and should be thought of as an alternative from that POV); however, marketing it as a way to render your Python app in JS doesn't appeal to me for any new project.
- bsimpson 12y agoTo that end, I wonder if the virtual DOM aspect of React could/should be broken out into its own library. You could have different templating languages up front to suit different use cases/programming styles, but each would be converted to DOM in the fastest way possible by React's renderer. There are so many awesome things that React's model enables (like live editing with react-hot-loader). It would be awesome if the next generation of templating languages could inherit them for effectively free.
- lomnakkus 12y agoWhat, you mean like virtual-dom[1]? [1] https://github.com/Matt-Esch/virtual-dom https://github.com/Matt-Esch/virtual-dom
- jquery 12y agoWhy is the top comment on Hacker News always a nay-sayer? Not everyone is working on greenfield projects. Nunjucks is a huge improvement for many large codebases.
- ezequiel-garzon 12y agoWell, right now there are three top-level comments, and the one you refer to is the only one of those presenting more than a sentence. Also, it seems to be no longer ranked first. In any event, I must say I like this kind of comments: a bit opinionated but putting forth some rationale, and hence inviting a healthy exchange of opinions.
- aikah 12y ago> and hence inviting a healthy exchange of opinions. There is no "inviting a healthy exchange of opinions",he is basically just trashing the project.There is nothing interesting in what he is saying,though he's free to say whatever he wants.Proof is the answers to his comment.
- baddox 12y agoI don't consider a qualified statement of preference to be "nay-saying." If the article was about React, someone claiming to prefer Nunjucks would be "nay-saying." Since it's about Nunjucks, someone claiming to prefer React is "nay-saying."
- aikah 12y agoI personally dislike react templating, and not everything is meant to be a single page app. So your way of doing things isnt definetly not as smart as you think.
- realusername 12y agoReact is not really like Angular, you can use it to improve a page by adding new components, you don't have to use React for everything like you would do with Angular. But yeah, I'm not really a huge fan of the template system either and the whole jsx thing is not really convenient.
- aikah 12y agoWell,I didnt talk about AngularJS. I talked about SPAs and the fact that I dont like React templates and JSX in general.
- findjashua 12y agoSlightly off-topic, but have you tried Ractive? I found it's 'ideology' similar to React (reusable components, virtual dom), but less verbose.
- sigil 12y agoI've been using Nunjucks client side and Flask + Jinja2 server side for about a year now. While there's some duplicate effort, it's not as bad as you might imagine. The duplicate effort: porting some custom Jinja2 filters and plugins from Python to JS. That was a few hours of work on a project that has seen thousands of hours of total work, so down in the noise really. If Python on the server side has big benefits in your problem space, don't let this deter you. The other thing to be aware of if you want isomorphic templating across JS and Python: Nunjucks is a subset of Jinja2. When I did the Jinja2 -> Nunjucks port, probably 95% of things just worked. The other 5% was either language-idiosyncratic stuff (for example {% set foo = 'bar' %} is scoped to the current block in Nunjucks, but leaks out of block scope in Jinja2) or places where I was being unnecessarily fancy in templates. The port forced me to keep my templates simple and not use the more exotic features of Jinja2, which has turned out to be a good thing.