You could cache the output, some thing like:

def generate_questionnaire_view():
       if is_cached_output_available():
              return get_cached_oputput()
       else:
              output_html = render_to_string(your parameters)
              add_to_cache(output_html)
              return output_html

The is_cached_output_available() function will check if we have some output 
cached, and nothing has changed since we cached the output.

Regards,
Mayuresh

http://twitter.com/geeroo
http://twitter.com/django_updates


On Monday, December 27, 2010 8:08:40 PM UTC+5:30, Guax3 wrote:
>
> I have a template in where I load a set of questions for a a 
> questionnaire, and each question has a set of options all this 
> information is retrieved from a database. so there's one for to 
> questions and another for to options, that gives: 
>
>  {% for question in questionnaire %} 
>     <tr><td colspan="3"><b>{{forloop.counter}}. {{ question }}</b></ 
> td></tr> 
>     <tr> 
>     {% for alternative in question.get_alternatives %} 
>         <td><input type="radio" name="{{question.id}}" 
> value="{{alternative.id}}"> {{ alternative }}</radio> 
>     {% endfor %} 
>     </tr> 
> {% endfor %} 
>
> The problem: depending on the number of questions, it can get pretty 
> heavy and time-consuming to retrieve all questionnaire from the 
> database. 
>
> My raw solution was to copy the output html code of all questionnaires 
> and save it on another "static" template, 
> I'm aware of the non-practicality of such so, here's my question: 
>
> Is there any pythonic-djangonic way to, in a lazy-loading style, 
> generate a template file where all the database retrieving was already 
> done and the whole html code was made, only regenerating this file if 
> something was changed in the database? 
>
> Did I made this question understandable? (I'm sorry, I'm a noob)

-- 
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