creating non-reloading dynamic webapps using Django

Question:

As far as I know, for a new request coming from a webapp, you need to reload the page to process and respond to that request.

For example, if you want to show a comment on a post, you need to reload the page, process the comment, and then show it. What I want, however, is I want to be able to add comments (something like facebook, where the comment gets added and shown without having to reload the whole page, for example) without having to reload the web-page. Is it possible to do with only Django and Python with no Javascript/AJAX knowledge?

I have heard it’s possible with AJAX (I don’t know how), but I was wondering if it was possible to do with Django.

Thanks,

Asked By: fengshaun

||

Answers:

You want to do that with out any client side code (javascript and ajax are just examples) and with out reloading your page (or at least part of it)?

If that is your question, then the answer unfortunately is you can’t. You need to either have client side code or reload your page.

Think about it, once the client get’s the page it will not change unless

  • The client requests the same page from the server and the server returns and updated one
  • the page has some client side code (eg: javascript) that updates the page.
Answered By: hhafez

To do it right, ajax would be the way to go BUT in a limited sense you can achieve the same thing by using a iframe, iframe is like another page embedded inside main page, so instead of refreshing whole page you may just refresh the inner iframe page and that may give the same effect.

More about iframe patterns you can read at
http://ajaxpatterns.org/IFrame_Call

Answered By: Anurag Uniyal

Maybe a few iFrames and some Comet/long-polling? Have the comment submission in an iFrame (so the whole page doesn’t reload), and then show the result in the long-polled iFrame…

Having said that, it’s a pretty bad design idea, and you probably don’t want to be doing this. AJAX/JavaScript is pretty much the way to go for things like this.

I have heard it’s possible with AJAX…but I was
wondering if it was possible to do
with Django.

There’s no reason you can’t use both – specifically, AJAX within a Django web application. Django provides your organization and framework needs (and a page that will respond to AJAX requests) and then use some JavaScript on the client side to make AJAX calls to your Django-backed page that will respond correctly.

I suggest you go find a basic jQuery tutorial which should explain enough basic JavaScript to get this working.

Answered By: Dan

You definitely want to use AJAX. Which means the client will need to run some javascript code.

If you don’t want to learn javascript you can always try something like pyjamas. You can check out an example of it’s HttpRequest here

But I always feel that using straight javascript via a library (like jQuery) is easier to understand than trying to force one language into another one.

Answered By: wm_eddie
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.