multi applications

6 views
Skip to first unread message

sjtirtha

unread,
Jul 14, 2009, 2:57:59 PM7/14/09
to django...@googlegroups.com
Hi,

I'm looking for documentation, which describes how to build a web application which includes many other applications.
For example like Facebook, it has following applications on the first screen:
1. On the left side is dynamic menu
2. In the middle is the microblogging
3. On the right side on the top is Request block
4. On the right side in the middle is Highlights

How can I build a web application like this? I was thinking to have a main application which has a template that includes all other applications.
But how can I set the context specific for every templates of the included applications?

regards,

Steve

Shawn Milochik

unread,
Jul 14, 2009, 3:10:57 PM7/14/09
to django...@googlegroups.com


There are several different aspects to what you are asking for and
describing. The first part is showing all the apps within one page,
and that's just a matter of a well-formatted CSS/HTML template. This
template may (should?) include smaller templates (for each section).

Ultimately your page will be called by a single URL, so you'll receive
the entire request in one place. From there, you will have to decide
how to handle the contexts. Look into the RequestContext class. The
things you need to display on all pages, regardless of what the "main"
view is at the moment, can be moved over there to avoid clutter.

The "main" content could be handled in the view called directly by
urls.py, and the rest can be inherited from the context dictionary
keys coming from your request contexts.

Also, you'll probably want/need to handle all the smaller apps on the
page with AJAX, because you won't want to refresh the entire page for
updating the microblog, etc. And since you're referring to FaceBook,
they even do most of the processing of actions in the "main" section
with AJAX, just to have a smoother user experience.

These are certainly vague answers. If this isn't what you're asking
for, please provide more detail.

Shawn


sjtirtha

unread,
Jul 14, 2009, 3:43:48 PM7/14/09
to django...@googlegroups.com
Thank you for the explanation.
This helps me very much.

You mentions about handling the smaller apps on the page with AJAX. Is there any basic functionality to do this from Django Framework?
Or do you have any ajax lib/framework as preference?

Steve

Shawn Milochik

unread,
Jul 14, 2009, 4:09:34 PM7/14/09
to django...@googlegroups.com

On Jul 14, 2009, at 3:43 PM, sjtirtha wrote:

> Thank you for the explanation.
> This helps me very much.
>
> You mentions about handling the smaller apps on the page with AJAX.
> Is there any basic functionality to do this from Django Framework?
> Or do you have any ajax lib/framework as preference?
>
> Steve

<snip>

Use jQuery -- it'll automate most of it.

Here are two simple samples. Both are in the $(document).ready()
function. Once you use jQuery for about three minutes, you'll know
what that is.

This does a GET request to get a user's current balance.
It then writes the balance (returned as JSON by the view)
into the HTML div with the id current_balance.

$.get("/balance_json/{{ch.slug}}", {}, function (data){
$('#current_balance').html("$" + data.balance);
}, 'json');


This does a POST to submit a form to send an SMS message. The view
also returns
JSON in this case, (created from a Python dictionary), which will
have a key of 'success'
with a value of the success message, or a key of 'failure' with an
error message in it.

$("#sms_form").submit(function(event){
event.preventDefault(); // stop the form from submitting and
refreshing the page
var data = $("#sms_form").serialize()

// now send the data to the server via AJAX
$.post("/patient/{{ch.slug}}/sms/", data, function(resp){
if(resp.success) {
$("#messages").html("<div id='success-message'
class='success'>" + resp.success + "</div>");
$("#success-message").animate({ backgroundColor:
"#E6EFC2" }, 2000);
update_activity();
} else if (resp.fail) {
$("#messages").html("<div id='fail-message'
class='fail'>" + resp.fail + "</div>");
$("#fail-message").animate({ backgroundColor:
"#fbe3e4" }, 2000);
}
}, "json");
});

I don't know if there are are super-special Django tools to do AJAX,
but as it's JavaScript and Django's Python, I doubt it.

The most useful things in Django are simplejson and safestring (both
in django.utils). You'll need simplejson to easily dump a dictionary
into a JSON string to pass back to JavaScript, and you'll need
safestring to "mark_safe" JSON strings you're going to pass via the
context to be rendered within the templates. Otherwise they'll be
escaped automatically for your protection.

Shawn

sjtirtha

unread,
Jul 14, 2009, 5:01:59 PM7/14/09
to django...@googlegroups.com
Hi,

thank you for the explanation. I'll look into it.
I found also an ajax lib for Django, it is DAJAX.
Steve
Reply all
Reply to author
Forward
0 new messages