Up the top of my head -

Create a separate ajax_content.html template for use with AJAX
requests (use an if statement in the view to determine which template
to load), then include ajax_content.html in the non-AJAX request
template to keep things DRY.

On 28 March 2010 12:29, David Hollander <dhll...@gmail.com> wrote:
> Hello. I am making a restaurant site with some visually candy that
> will load all new subpages via AJAX. And also load pages normally
> without AJAX if javascript is disabled.
>
> Ideally, I want to do:
>
> {% if not ajax %}
>    {% extends 'base.html' %}
> {% endif %}
> {% block content %}Content Here.{% endblock %}
>
> That way I can use the same template for an ajax request as a regular
> request. In a regular request where I pass ajax: False to the
> template, it will extend base.html and add all the background stuff
> such as html header, navigation menu, etc. But if it's ajax, it
> doesn't load any of that unnecessary stuff since that will already be
> present in the page with the ajax request.
> I know I can just return the whole page to an AJAX request and slice
> out the unncessary stuff with jQuery. Or I can create a seperate
> template for the AJAX version. But that would either be very
> inefficient OR violate the DRY principle.
>
> What is the best idiom to handle this situation?
>
> Thank you for your time.
> -David
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to