views:

285

answers:

4

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,

+6  A: 

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.

I can not imagine a third possibility. I have not coded in Django for more than 30 mins and this is clearly obvious to me. If I am wrong plz down vote :D

hhafez
he says - "without knowledge of javascript/AJAX" not "without javascript"
Evgeny
javascript and AJAX are not equivalent, I don't get your point? He only wants to use Django/Python only (ie no client side code) even tough you can generate the client code from Django/Python, but that is not what he wants to do. He wants no client code
hhafez
+1  A: 

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

Anurag Uniyal
+1  A: 

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.

Dan
+3  A: 

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.

wm_eddie