pjax_flask icon indicating copy to clipboard operation
pjax_flask copied to clipboard

Less-invasive way of accomplishing the same

Open coleifer opened this issue 13 years ago • 2 comments

The approach you describe is very invasive as it requires you to use a special function to render templates depending on whether it is pjax or not. It also does not allow for very good reuse of template blocks.

I use a different approach which comes at it the other way - via the templates. Essentially it entails swapping out base template based on whether the request is pjax or not. It does not require any special code inside the your flask application and does not require you to do anything differently in the templates. Here's a gist showing how I've set it up:

https://gist.github.com/0ffdd627542cf0de8af4

coleifer avatar Dec 29 '11 19:12 coleifer

Awesome! This is 100% a better solution — I hadn't even thought of using @app.context_processor.

Thank you. I'll update the app and page accordingly tonight.

zachwill avatar Dec 29 '11 20:12 zachwill

So glad you like it! No problemo, glad i could help. +1 for using flask :)

coleifer avatar Dec 29 '11 23:12 coleifer