django crispy forms overriding layout objects templates ignored
up vote
0
down vote
favorite
I applied this
thus I have
self.helper.layout = Layout(
Field(
'title', template="mytemplate.html"
) ,
As result my template is not rendered
helper.field_template is None in below code:
(C:myapplibcrispy_formstemplatetagscrispy_forms_filters.py):
@register.filter(name='as_crispy_field')
def as_crispy_field(field, template_pack=TEMPLATE_PACK, label_class="", field_class=""):
"""
Renders a form field like a django-crispy-forms field::
{% load crispy_forms_tags %}
{{ form.field|as_crispy_field }}
or::
{{ form.field|as_crispy_field:"bootstrap" }}
"""
if not isinstance(field, forms.BoundField) and settings.DEBUG:
raise CrispyError('|as_crispy_field got passed an invalid or inexistent field')
attributes = {
'field': field,
'form_show_errors': True,
'form_show_labels': True,
'label_class': label_class,
'field_class': field_class,
}
helper = getattr(field.form, 'helper', None)
template_path = None
if helper is not None:
attributes.update(helper.get_attributes(template_pack))
template_path = helper.field_template
if not template_path:
template_path = '%s/field.html' % template_pack
template = get_template(template_path)
c = Context(attributes).flatten()
return template.render(c)
if I modify helper.field_name on debug to mytemplate.html, I see it is rendered with success.
Question is what could be reason that my template is ignored?
Important note, my form extends:
class RoomForm(ModelForm)
where ModelForm
is as here
In my form I render with:
{{ form.title | as_crispy_field }}
and relevant part of my view is:
form = RoomForm(None, prefix="submit-room" )
return render(request, 'edit_room.html', { 'form': form })
finally mytemplate.html is, copied "everywhere":
C:myapplibcrispy_formstemplatesbootstrap4
and C:myapptemplatesmytemplate.html
{% load custom_tags %}
<div>tutu</div>
<div>{{field}}</div>
python django django-templates django-crispy-forms
add a comment |
up vote
0
down vote
favorite
I applied this
thus I have
self.helper.layout = Layout(
Field(
'title', template="mytemplate.html"
) ,
As result my template is not rendered
helper.field_template is None in below code:
(C:myapplibcrispy_formstemplatetagscrispy_forms_filters.py):
@register.filter(name='as_crispy_field')
def as_crispy_field(field, template_pack=TEMPLATE_PACK, label_class="", field_class=""):
"""
Renders a form field like a django-crispy-forms field::
{% load crispy_forms_tags %}
{{ form.field|as_crispy_field }}
or::
{{ form.field|as_crispy_field:"bootstrap" }}
"""
if not isinstance(field, forms.BoundField) and settings.DEBUG:
raise CrispyError('|as_crispy_field got passed an invalid or inexistent field')
attributes = {
'field': field,
'form_show_errors': True,
'form_show_labels': True,
'label_class': label_class,
'field_class': field_class,
}
helper = getattr(field.form, 'helper', None)
template_path = None
if helper is not None:
attributes.update(helper.get_attributes(template_pack))
template_path = helper.field_template
if not template_path:
template_path = '%s/field.html' % template_pack
template = get_template(template_path)
c = Context(attributes).flatten()
return template.render(c)
if I modify helper.field_name on debug to mytemplate.html, I see it is rendered with success.
Question is what could be reason that my template is ignored?
Important note, my form extends:
class RoomForm(ModelForm)
where ModelForm
is as here
In my form I render with:
{{ form.title | as_crispy_field }}
and relevant part of my view is:
form = RoomForm(None, prefix="submit-room" )
return render(request, 'edit_room.html', { 'form': form })
finally mytemplate.html is, copied "everywhere":
C:myapplibcrispy_formstemplatesbootstrap4
and C:myapptemplatesmytemplate.html
{% load custom_tags %}
<div>tutu</div>
<div>{{field}}</div>
python django django-templates django-crispy-forms
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I applied this
thus I have
self.helper.layout = Layout(
Field(
'title', template="mytemplate.html"
) ,
As result my template is not rendered
helper.field_template is None in below code:
(C:myapplibcrispy_formstemplatetagscrispy_forms_filters.py):
@register.filter(name='as_crispy_field')
def as_crispy_field(field, template_pack=TEMPLATE_PACK, label_class="", field_class=""):
"""
Renders a form field like a django-crispy-forms field::
{% load crispy_forms_tags %}
{{ form.field|as_crispy_field }}
or::
{{ form.field|as_crispy_field:"bootstrap" }}
"""
if not isinstance(field, forms.BoundField) and settings.DEBUG:
raise CrispyError('|as_crispy_field got passed an invalid or inexistent field')
attributes = {
'field': field,
'form_show_errors': True,
'form_show_labels': True,
'label_class': label_class,
'field_class': field_class,
}
helper = getattr(field.form, 'helper', None)
template_path = None
if helper is not None:
attributes.update(helper.get_attributes(template_pack))
template_path = helper.field_template
if not template_path:
template_path = '%s/field.html' % template_pack
template = get_template(template_path)
c = Context(attributes).flatten()
return template.render(c)
if I modify helper.field_name on debug to mytemplate.html, I see it is rendered with success.
Question is what could be reason that my template is ignored?
Important note, my form extends:
class RoomForm(ModelForm)
where ModelForm
is as here
In my form I render with:
{{ form.title | as_crispy_field }}
and relevant part of my view is:
form = RoomForm(None, prefix="submit-room" )
return render(request, 'edit_room.html', { 'form': form })
finally mytemplate.html is, copied "everywhere":
C:myapplibcrispy_formstemplatesbootstrap4
and C:myapptemplatesmytemplate.html
{% load custom_tags %}
<div>tutu</div>
<div>{{field}}</div>
python django django-templates django-crispy-forms
I applied this
thus I have
self.helper.layout = Layout(
Field(
'title', template="mytemplate.html"
) ,
As result my template is not rendered
helper.field_template is None in below code:
(C:myapplibcrispy_formstemplatetagscrispy_forms_filters.py):
@register.filter(name='as_crispy_field')
def as_crispy_field(field, template_pack=TEMPLATE_PACK, label_class="", field_class=""):
"""
Renders a form field like a django-crispy-forms field::
{% load crispy_forms_tags %}
{{ form.field|as_crispy_field }}
or::
{{ form.field|as_crispy_field:"bootstrap" }}
"""
if not isinstance(field, forms.BoundField) and settings.DEBUG:
raise CrispyError('|as_crispy_field got passed an invalid or inexistent field')
attributes = {
'field': field,
'form_show_errors': True,
'form_show_labels': True,
'label_class': label_class,
'field_class': field_class,
}
helper = getattr(field.form, 'helper', None)
template_path = None
if helper is not None:
attributes.update(helper.get_attributes(template_pack))
template_path = helper.field_template
if not template_path:
template_path = '%s/field.html' % template_pack
template = get_template(template_path)
c = Context(attributes).flatten()
return template.render(c)
if I modify helper.field_name on debug to mytemplate.html, I see it is rendered with success.
Question is what could be reason that my template is ignored?
Important note, my form extends:
class RoomForm(ModelForm)
where ModelForm
is as here
In my form I render with:
{{ form.title | as_crispy_field }}
and relevant part of my view is:
form = RoomForm(None, prefix="submit-room" )
return render(request, 'edit_room.html', { 'form': form })
finally mytemplate.html is, copied "everywhere":
C:myapplibcrispy_formstemplatesbootstrap4
and C:myapptemplatesmytemplate.html
{% load custom_tags %}
<div>tutu</div>
<div>{{field}}</div>
python django django-templates django-crispy-forms
python django django-templates django-crispy-forms
edited Nov 21 at 18:13
asked Nov 21 at 13:01
asdf_enel_hak
6,03032664
6,03032664
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I don't want to change question purpose to much that I can answer it with the inputs so far I got:
self.helper.layout = Layout(
Field(
'title', template="mytemplate.html"
)
Successfully sets individual fields template but as_crispy_field
does not care it but it takes form template value instead.
If I render as form with, it works perfectly.
{% crispy form %}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I don't want to change question purpose to much that I can answer it with the inputs so far I got:
self.helper.layout = Layout(
Field(
'title', template="mytemplate.html"
)
Successfully sets individual fields template but as_crispy_field
does not care it but it takes form template value instead.
If I render as form with, it works perfectly.
{% crispy form %}
add a comment |
up vote
0
down vote
I don't want to change question purpose to much that I can answer it with the inputs so far I got:
self.helper.layout = Layout(
Field(
'title', template="mytemplate.html"
)
Successfully sets individual fields template but as_crispy_field
does not care it but it takes form template value instead.
If I render as form with, it works perfectly.
{% crispy form %}
add a comment |
up vote
0
down vote
up vote
0
down vote
I don't want to change question purpose to much that I can answer it with the inputs so far I got:
self.helper.layout = Layout(
Field(
'title', template="mytemplate.html"
)
Successfully sets individual fields template but as_crispy_field
does not care it but it takes form template value instead.
If I render as form with, it works perfectly.
{% crispy form %}
I don't want to change question purpose to much that I can answer it with the inputs so far I got:
self.helper.layout = Layout(
Field(
'title', template="mytemplate.html"
)
Successfully sets individual fields template but as_crispy_field
does not care it but it takes form template value instead.
If I render as form with, it works perfectly.
{% crispy form %}
answered Nov 21 at 19:56
asdf_enel_hak
6,03032664
6,03032664
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412634%2fdjango-crispy-forms-overriding-layout-objects-templates-ignored%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown