Goal: produce responses for both ajax and regular requests with a
single render_to_response call and no extraneous templates.
Solution:
1. dynamic extends. mypage.html: {% extends base %}.
base="mybase.html" or "ajaxbase.html"
pros: one render_to_response call.
cons: Have to create extra dummy
I implemented two solutions for this problem. The first one is the solution
already said here: create a template context processor that inserts a
variable in context with the name of the base template ("base.html" for
normal requests and "base_ajax.html" for ajax requests).
The second one is a
Ideally, I want to do:
>
> {% if not ajax %}
> {% extends 'base.html' %}
> {% endif %}
> {% block content %}Content Here.{% endblock %}
Extends can't be optional. Consider the following:
base_template.html:
Foo
{% block foo %}{% endblock %}
Bar
{% block bar %}{% endblock %}
Something I tried once: set the 'extends' template variable in your
views (middleware even, maybe) to either an empty string or the path
to your template, based on the result of request.is_ajax.
I'm not sure though whether Django will throw an error if extends has
an empty string.
Suggestion:
On Sat, Mar 27, 2010 at 9:29 PM, David Hollander 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
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
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.{%
7 matches
Mail list logo