librelist archives

« back to archive

Routing to links using variables defined in knockoutjs

Routing to links using variables defined in knockoutjs

From:
Chitrank Dixit
Date:
2013-11-08 @ 20:12
Hello Flask Developers

I am using url_for() to route to a particular view and it is working fine
with variables that I render in html.

But the variables that are passed to the page using jsonify are received
under knockout code and then I am able to print up things but not able to
route to the particular url with the parameters . I am fed up with finding
a solution on the web and I have not got any right way to solve this issue,
please help me out with this

Here is my question at stackoverflow

http://stackoverflow.com/questions/19784956/using-jinja2-template-under-knockout-attr-binding


*Regards*

*Chitrank Dixit*

*IIPS-DAVV*
*Indore (M.P.) , India *

*MCA*
*trackleech.blogspot.in <http://trackleech.blogspot.in>*

Re: [flask] Routing to links using variables defined in knockoutjs

From:
Daniel Fairhead (OMNIvision)
Date:
2013-11-10 @ 14:54
Hi Chitrank!

Sorry it's been frustrating for you.  I posted a reply on stackoverflow, 
hopefully thats helpful. ( http://stackoverflow.com/a/19890903/1973500 ).

I'm using flask with knockoutjs every day at work here, it's a very nice
combination. It does take a little bit different thinking from purely 
flask view + template way of working. You need to take a lot more of 
your templating code and render it on the client side inside the 
web-browser, rather than using jinja on the server.

I've found that if I try and mix jinja templating code with knockout 
templating code that I run into problems.  You need to treat them as 
totally separate systems, and pass pure data (usually JSON) back and 
forth.  Either have a JSON view using flask-RESTful or similar, or else 
embed the JSON at the end of your jinja page:

<html...>
...
    <!-- pure knockout templatey stuff, with no mention of anything
         jinja related at all here. -->
...
<script type="text/javascript" src="my-knockout-models.js"></script>
<script type="text/javascript">
POSTS_DATA={{ posts |tojson|safe }};
posts = new PostsView( POSTS_DATA );
ko.applyBindings(posts);
</script>

which loads the data straight away, rather than sending another async 
request after page load.

Have fun!  And feel free to ask more questions. (I'm OK with direct 
emails if you want to ask off-list as well).

Dan

On 11/08/2013 08:12 PM, Chitrank Dixit wrote:
> Hello Flask Developers
>
> I am using url_for() to route to a particular view and it is working
> fine with variables that I render in html.
>
> But the variables that are passed to the page using jsonify are received
> under knockout code and then I am able to print up things but not able
> to route to the particular url with the parameters . I am fed up with
> finding a solution on the web and I have not got any right way to solve
> this issue, please help me out with this
>
> Here is my question at stackoverflow
> 
http://stackoverflow.com/questions/19784956/using-jinja2-template-under-knockout-attr-binding
>
> *Regards
> *
> *Chitrank Dixit
> *
> *IIPS-DAVV
> *
> *Indore (M.P.) , India *
> *MCA
> *
> *trackleech.blogspot.in <http://trackleech.blogspot.in>*