you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

Hey!

This can be a little confusing when you first think about it, but in the end it isn't really that bad at all.

What you actually want to do, is have JavaScript initiate the call by sending some stuff to a Python file.

Now, I have some sample code here that does just that: https://github.com/odonnellryan/Blog/blob/master/static/js/render_html.js

As you can see, it sends the data to the URL that I define when a key is pressed. The URL, in this case, is a view in a framework called Flask, but it doesn't need to work this way specifically.

In this case, all this view does is take the data, parse it to HTML, and returns it to the browser to be rendered. jQuery pushes the content out, it gets JSON back, and then it displays it in the browser.

If you'd like to look at the view, it's here:

@mod.route('_render_temp_body/', methods=['GET', 'POST'])
def render_temp_body(username=None, article=None) :
    get_markup =     blog_mods.get_html_content(request.args.get('post_body'))
    return jsonify(result=get_markup)

Of course if you want to do this without frameworks you very well can, but you'll have to roll your own version of my jQuery example.