new forms - processing the form without rebuilding the entire view

1 view
Skip to first unread message

Tipan

unread,
Apr 13, 2007, 10:29:18 AM4/13/07
to Django users
I've created a view that is made up of several elements such as main
content, sidebar information navigation bar. The main content is
derived from specific data dependent on the parameter passed to the
view. .../page/3 etc.

The view is rendered as a series of template extensions from a master
base.html. Elements also use inclusion tags.

I want to include a form field in the main part of the view and have
displayed this as an inclusion tag. The purpose of the form is to
enable a user to enter a code which can be checked in the database.
Error messages need to be returned to this view, if code is valid the
user will be passed to a new view.

However, I'm not sure of the best way to process the form for error
messages without rebuilding the complete view, which seems to be a lot
of overhead when you consider all the relevant queries that have to be
re-done.

Can any one advise on best practice here, or a means by which I can
cache the original view?

xgdlm

unread,
Apr 14, 2007, 6:21:09 AM4/14/07
to Django users

> However, I'm not sure of the best way to process the form for error
> messages without rebuilding the complete view, which seems to be a lot
> of overhead when you consider all the relevant queries that have to be
> re-done.

Multiple way to process this in my opinion :

1- cache the elements of the page that can be cached with the django
caching api
2- use ajax to process your form. This will avoid the whole page to be
reload. For exemple when the form is fired, process an ajax request
and evaluate a JSON or HTML repsonse.

xav

Tipan

unread,
Apr 16, 2007, 5:55:09 AM4/16/07
to Django users
Thanks xav, I thought that the answer might involve both caching and
Ajax but I wasn't sure how. I'm not familiar with either so I'll need
to go through the documentation. Do you know where I can find some
good examples of using these?

Tim

Georgi Stanojevski

unread,
Apr 16, 2007, 7:50:08 AM4/16/07
to django...@googlegroups.com
Tipan напиша:

http://www.b-list.org/weblog/2006/08/05/django-tips-simple-ajax-example-part-2
With YUI javascript library.

http://code.djangoproject.com/wiki/AJAX/Dojo/RefactoredFormSubmit
With DOJO javascript library.

http://code.djangoproject.com/wiki/AjaxPrototypeNewForms
With Prototype javascript library.


--
Glisha
The perfect OS, MS-DOS!
No patches, no root exploits for 21 years.

Nathaniel Whiteinge

unread,
Apr 16, 2007, 3:28:00 PM4/16/07
to Django users
I'm doing something pretty similar sounding with jQuery. I wanted to
check for form validation errors via Ajax and do a regular form
submission otherwise.

The JavaScript:
http://dpaste.com/hold/8571/

The Python:
http://dpaste.com/hold/8572/

The code might be a little weird looking. I'm relying on a 403
response header to detect validation errors and the X-Requested-With
request header to detect Ajax.

Feel free to drop me a line for more explanation if you want.
- whiteinge

Tipan

unread,
Apr 18, 2007, 5:11:59 AM4/18/07
to Django users
Thanks Guys,

I've read through all the links and I can see plenty of scope with
Ajax/JSON.

I note that most of the solutions use a Javascript toolkit such as
Prototype/Dojo/Yahoo/JQuery. Two questions come to mind:

1. Does using the toolkit save a lot of work - what are the main
advantages?
2. How do you choose between them?

Tim

Nathaniel Whiteinge

unread,
Apr 18, 2007, 3:26:52 PM4/18/07
to Django users
Personally, I use a toolkit to lessen cross-browser compatibility
problems as well as to speed quick, little functionality (eg.
animations). I chose jQuery because it's small, unobtrusive, and I
love the CSS-like syntax.
- whiteinge

Tipan

unread,
Apr 20, 2007, 2:40:51 AM4/20/07
to Django users

On Apr 18, 8:26 pm, Nathaniel Whiteinge <whitei...@gmail.com> wrote:
> Personally, I use a toolkit to lessen cross-browser compatibility
> problems as well as to speed quick, little functionality (eg.
> animations). I chose jQuery because it's small, unobtrusive, and I
> love the CSS-like syntax.
> - whiteinge
>

Thanks - I can see the reasoning. We've used JQuery on a small PHP
site we did, but only to provide some nice tab effects. It was
reasonably straightforward to use, even for a JS novice. Will give it
a go on our Ajax work in Django too.
-Tim

Reply all
Reply to author
Forward
0 new messages