django crispy forms overriding layout objects templates ignored












0















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>









share|improve this question





























    0















    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>









    share|improve this question



























      0












      0








      0








      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>









      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 18:13







      asdf_enel_hak

















      asked Nov 21 '18 at 13:01









      asdf_enel_hakasdf_enel_hak

      6,05832664




      6,05832664
























          1 Answer
          1






          active

          oldest

          votes


















          0














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





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            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

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














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





            share|improve this answer




























              0














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





              share|improve this answer


























                0












                0








                0







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





                share|improve this answer













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






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 19:56









                asdf_enel_hakasdf_enel_hak

                6,05832664




                6,05832664






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Create new schema in PostgreSQL using DBeaver

                    Deepest pit of an array with Javascript: test on Codility

                    Costa Masnaga