May 29, 2016

Free Herbal Viagra Samples

Free herbal viagra samples –or–

Free herbal viagra samples “How your mobile site may not be much more complicated than building one with a data API or AJAX”

Free herbal viagra samples I am working on a project called ‘IvyRoot’ that is predominantly mobile and which is going to make me fabulously rich and famous.

OK, free herbal viagra samples OK. Free herbal viagra samples It’s predominantly mobile, free herbal viagra samples at least. Free herbal viagra samples It’s all in Django.

Free herbal viagra samples There’s a ‘desktop’ web site to go with it, free herbal viagra samples and this contains panels within pages. Free herbal viagra samples Some of these panels might take a few moments to process and so I use XHR to call back to get them once the main page has loaded, free herbal viagra samples displaying a pretty spinning icon in the meantime.

Free herbal viagra samples I also use XHR to populate in-page tables which might have many rows – so that pagination and sorting are fast without having to load the whole page again.

Free herbal viagra samples I also want to expose a number of data APIs (providing XML, free herbal viagra samples JSON, free herbal viagra samples basic HTML and the like) so that people can build 3rd party clients, free herbal viagra samples their own consuming sites, free herbal viagra samples and widgets.

Free herbal viagra samples Finally, free herbal viagra samples I want to provide a mobile web version of the site. Free herbal viagra samples I’ll probably do some sort of device detection to refine the behaviour, free herbal viagra samples but I should assume that plenty of browsers will not be able to do the XHR bit, free herbal viagra samples and should have the page (containing all the panels) in one go – admittedly after a slightly longer wait.

Free herbal viagra samples Well, free herbal viagra samples it occurs to me that these requirements can all be solved at the same time. Free herbal viagra samples Switching templates based on URL (or other HttpRequest clues) is pretty easy, free herbal viagra samples so one thing I could do is have a filename extension convention for all my URLs. Free herbal viagra samples Imagine a ‘things’ view that lists things.

  • – this is the human-consumable page: the view surrounded by menus, free herbal viagra samples logos, free herbal viagra samples graphics and the like. Free herbal viagra samples Knows how to switch outer template, free herbal viagra samples based on various things, free herbal viagra samples between desktop and mobile.
  • – this is the table at the heart of the page, free herbal viagra samples perhaps using unstyled markup containing the list of things itself.
  •, free herbal viagra samples etc – data APIs that list things in various serializations.

Free herbal viagra samples So perhaps we can set up URL routes like this:

(r'^things$', free herbal viagra samples things), free herbal viagra samples
(r'^things.(?P<mode>[a-z0-9]+)$', free herbal viagra samples things), free herbal viagra samples

Free herbal viagra samples And have a view that looks something like this:

def things(request, free herbal viagra samples mode=''):
    if not mode:
        mode = desktop_or_mobile()
    template = "things.%s" % mode

Free herbal viagra samples (Or, free herbal viagra samples I suppose we could pass the mode into the template via the context and have some sort of a switch statement in the template itself. Free herbal viagra samples It might be good to pass it in, free herbal viagra samples anyway, free herbal viagra samples in case there is any further refinement required within each template.)

Free herbal viagra samples Anyway, free herbal viagra samples let’s also assume that the things list is very long and takes a while to generate. Free herbal viagra samples For the desktop users, free herbal viagra samples we might want to either load the table as HTML asynchronously using XHR, free herbal viagra samples or paged into a jQuery grid control. Free herbal viagra samples For these two approaches, free herbal viagra samples I can call back to /things.html or /things.json respectively (and do a little extra plumbing to make sure the JSON is in the right format for the grid control to consume).

Free herbal viagra samples But what of mobile? Well, free herbal viagra samples for many devices, free herbal viagra samples I can’t expect any XHR activity to be supported, free herbal viagra samples so we need to insert the table HTML into the body of the page before it departs for the client – and we may need to pre-page it too (if it’s long). Free herbal viagra samples But the good news is that, free herbal viagra samples if I made it simple enough, free herbal viagra samples the HTML generated by things.html might be good enough for either type of browser.

Free herbal viagra samples (And if not, free herbal viagra samples I could easily do a little adaptation on that view too – perhaps turn my table into a list.)

Free herbal viagra samples So what I would like to have a is a way of embedding the output of one view (or even URL) into another, free herbal viagra samples whilst the response is still being put together on the server. Free herbal viagra samples Try as I could, free herbal viagra samples there didn’t seem to be anything in Django to do this.

Free herbal viagra samples Enter my first DjangoSnippet!

Free herbal viagra samples This basically allows me to put a template tag into the mobile template that pulls the output from one of the other views (identified by view name, free herbal viagra samples with arguments; or a verbatim URL which would be the same as the one used in the desktop’s XHR request – nifty!)

Free herbal viagra samples It also makes sure that the context for that view is sandboxed with what it needs to render itself – so that I don’t have to worry about getting the context ready in the ‘outer’ view. Free herbal viagra samples That’s not necessary in our simple example above – but it might be useful later on if I am dynamically choosing which panels to place on a page, free herbal viagra samples and I want them to gather together their own context prior to template rendering.

Free herbal viagra samples Now, free herbal viagra samples I’ll need to be careful to make sure that any interaction elements within the table – say, free herbal viagra samples some actions available on each item in the list, free herbal viagra samples or a paginator – behave suitably for their location. Free herbal viagra samples But this may be as simple as toggling between further XHR requests (for desktop) and simple anchor links (for mobile). Free herbal viagra samples Forms-in-panels will be harder but similar.

Free herbal viagra samples So… there we are, free herbal viagra samples a glimpse at the inner workings of a mystery application that’s many weeks away from seeing the light of day.

Free herbal viagra samples But hopefully I’ve raised a few thoughts about how you can treat the mobile version of your site as being a cousin of the data APIs that you might have written anyway. Free herbal viagra samples And also how you might be able to sneakily bring some of the funky XHR – that you wanted to impress your friends with on the desktop – up into the server to keep your mobile pals happy too.

Average Rating: 5 out of 5 based on 259 user reviews.

Comments (12)

  1. June 17, 2009
    Bryan Rieger said...

    Very nice idea indeed. I the fact that you’re still able to support both clients with and without Javascript using this approach.

    BTW – nice note on 😉

  2. June 17, 2009
    Paul said...

    Neat. I think this approach has applications beyond the mobile/XHR context, too, though they may not be quite as interesting. Could eliminate the need for custom inclusion tags in some cases.

    Specifying output format via filename extension is simple and REST-y. Takes me back to the first piece of software I saw that did that dynamically and well: Blosxom.

    (Found this via the Djangosnippets Twitter feed, BTW.)

  3. July 16, 2009
    Steve Anderson said...

    One thing to be wary of with Django, is that switching templates in real time based on the request is NOT THREAD SAFE, and you must be extremely careful to reset any settings that you modify at runtime. The Django docs ( display a very mysterious message simply telling us never to do anything of the sort, but don’t really explain why!

    This talk by Simon Willison sums up a few of the annoying things about, one of which being that changing settings at runtime is not thread safe –

    I unfortunately learned this when trying to write my own mobilization middleware for Django ( I’m still looking for a decent way to do dynamic template switching with Django, but the globalness of makes this a bit difficult.

    Simon has suggested some improvements (, but of course this involves some significant reworking of the Django core.

    I think we definitely need to look into a better way of doing this for Django, as it is a growing need of a lot of apps built in the framework. It’d be good to hear your thoughts…

  4. July 16, 2009
    Steve Anderson said...

    I’ve just realized that you actually do this in quite a nice way, by building up the string in your view and calling render on the correct template. Makes sense. I must have misread.

    Even so, it’s handy to know about changing settings on the fly being dangerous.

  5. July 19, 2009
    James said...

    Hi Steve,

    w.r.t. to mobilization, I use middleware that decides which page to display (based on this algorithm) and then pops its decision into the request object.

    A context processor then puts the master mobile-or-desktop template name into a universal context variable called page_template, and then my page.html template (which all pages derive from) is literally just:

    {%extends page_template%}

    (NB: page_template is a variable, not a literal – that’s the trick)

    I then just need something like and page.desktop.html with the appropriate skeleton of the two types of page (but with mostly the same key blocks), that this extends tag will refer to.

    … in other words I am able to dictate the top-level look from the incoming request without doing anything too unnatural with respect to templates and settings 🙂

    I need to write this up I guess.

  6. July 21, 2009
    Steve said...

    That’s pretty nifty.

    It’s things like this that make me love Django 🙂

    I was thinking of extending the built in Template object and render_to_response function to decide which template to use (mobile, json, xml, desktop etc.), meaning you could take that little bit of code out of your views.

  7. November 10, 2010
    Mike said...

    I found your blog on bing and will bookmark it now. Keep up the nice work.

  8. June 13, 2015
    Henty said...

    django.views.generic.simple.direct_to_template takes request as the first paamreter and does the same thing, in addition to providing URL paamreters. Here’s the source, from django/views/generic/ direct_to_template(request, template, extra_context=None, mimetype=None, **kwargs): “”” Render a given template with any extra URL paamreters in the context as “{{ params }}“. “”” if extra_context is None: extra_context = {} dictionary = {‘params’: kwargs} for key, value in extra_context.items(): if callable(value): dictionary[key] = value() else: dictionary[key] = value c = RequestContext(request, dictionary) t = loader.get_template(template) return HttpResponse(t.render(c), mimetype=mimetype)

  9. July 22, 2015

    There’s nothing like the relief of finding what you’re looking for.

  10. September 22, 2015

    Your story was really informative, thanks!

  11. September 22, 2015

    It’s imperative that more people make this exact point.

  12. September 29, 2015

    Touchdown! That’s a really cool way of putting it!

Leave a Reply