Slow rendering on Django 1.7 if Layout objects
See original GitHub issueHello,
I’ve been using django crispy forms for quite a while now, and never noticed this issue until now. Maybe it comes from my syntax uising the Layout and Div object. I have DCF 1.4.0.
As soon as I’m using the layout.Layout object with some div inside, the time for rendering the form is extremely slow (1.5 second instead of 100ms).
I have a very simple form:
class TAFilterForm(forms.Form):
subject = forms.CharField(required=False)
ss = forms.ChoiceField(choices=models.SS_CHOICES, required=False)
min_created_at = forms.DateField(required=False)
max_created_at = forms.DateField(required=False)
aa = forms.ChoiceField(choices=models.AA_CHOICES, required=False)
cc = forms.ChoiceField(required=False)
id = forms.CharField(required=False)
def __init__(self, *args, **kwargs):
super(TAFilterForm, self).__init__(*args, **kwargs)
self.fields['cc'].choices = (('all', _('All')), )
self.helper = helper.FormHelper()
self.helper.form_method = 'GET'
self.helper.add_input(
layout.Submit('submit', _('Filter')),
)
self.helper.add_input(
layout.Submit('csv', _('Get CSV')),
)
self.helper.layout = layout.Layout(
layout.Div(
layout.Div('id', css_class='span3'),
layout.Div('ss', css_class='span3'),
layout.Div('aa', css_class='span3'),
layout.Div('cc', css_class='span3'),
css_class='row-fluid filter-form-div',
),
layout.Div(
layout.Div('subject', css_class='span4'),
layout.Div('min_created_at', css_class='span4'),
layout.Div('max_created_at', css_class='span4'),
css_class='row-fluid filter-form-div',
),
)
thanks
Issue Analytics
- State:
- Created 9 years ago
- Comments:6
Top Results From Across the Web
Django rendering a page with a large selection. Could this be ...
I render a .html page using django. The html page contains instances of artist . class Artist(EmptyModelBase): name = models.CharField( ...
Read more >Fixed a slow render of a template - Django Forum
I was having a performance problems in my template. It was taking 15 seconds to render with 280 queries. Which seemed slow.
Read more >Top 10 Mistakes That Django Developers Make - Toptal
In this tutorial, we will look at some common mistakes that are often made by Django developers and ways to avoid them. This...
Read more >The Build — High Performance Django - Lincoln Loop
Building a high-traffic site from scratch is a dangerous undertaking. There are lots of places Django can be optimized and it's easy to...
Read more >How to Optimize Django ORM Queries - Gearheart
Django ORM is a very abstract and flexible API. But if you do not know exactly how it works, you will likely end...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Using django’s cached template loader helps speed things up immensely.
Use this code in your settings.py file to use the cached template loader.
Without caching even without a Layout object crispy forms seems to take forever to render forms with many fields or formsets with many forms. By using the loader I brought a formset with 8 forms of 3 fields each from 10s rendering time down to 500ms on subsequent loads.
It’s worthing looking at the FAQ, which discusses this too. http://django-crispy-forms.readthedocs.io/en/latest/faq.html?highlight=cache#how-fast-is-django-crispy-forms
I’m going to close this as I don’t think it’s an issue per se. (Happy to reconsider if enlightened suggestions arise.)