0

I have installed wagtail Streamforms package latest release and wagtail 2.0 , but when I created the form using it and the form content is not showning with the default form template and when I defined a custom template 'streamforms/form_block.html' still the content of the form it's not showing up.I have defined both the templates I am using in my base.py file of setting as said in the doc.

WAGTAILSTREAMFORMS_FORM_TEMPLATES = ( ('streamforms/form_block.html', 'Default Form Template'), )

But in admin panel->Streamforms when I am creating a form ,in the template chooser field it's just showing "Default Form Template"

I have defined it in models.py in streamfields and defined myself the template to show the content it not rendering still class StandardPage(Page):

class StandardPage(Page):
    introduction = models.TextField(
        help_text='Text to describe the page',
        blank=True)
    image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+',
        help_text='Landscape mode only; horizontal width between 1000px and 3000px.'
    )
    video_url = models.URLField(
        null=True,
        blank=True
    )
    body = StreamField([
        (
            'main_content',
            blocks.ListBlock(BaseStreamBlock(), label='content')
        ),
        (
            'form',
            blocks.ListBlock(WagtailFormBlock(), label='create form')
        )
    ,],
        blank=True,
        null=True,
        verbose_name="Standard Page"
    )

    content_panels = Page.content_panels + [
        FieldPanel('introduction', classname="full"),
        ImageChooserPanel('image'),
        FieldPanel('video_url'),
        StreamFieldPanel('body'),
    ]

    @property
    def standard_page(self):
        return self.get_parent().specific

This is my "Standard_Page.html" template

    {% extends "base.html" %}
{% load wagtailcore_tags wagtailtrans_tags streamforms_tags wagtailimages_tags homeapp_tags%}



 {% block content%}


{% include "base/include/header.html" %}
    <div class="container">
{{ page.introduction }}
     {{ page.image }}

        <div class="row">
            <div class="col-md-7">
               {% for block in page.body %}
                {{ block}}
{% endfor %}
            </div>

        </div>
        </div>
{% endblock  %}

What I am doing wrong?

  • Please add the complete model. Where are the panels? – allcaps Jul 08 '18 at 19:56
  • I have edited the question.Now, you can see, the complete model I defined.Any help, what I need to do. – divya chauhan Jul 09 '18 at 05:35
  • I have reformatted your Python code. Did you follow the documentation on WagtailFormBlock. This is how you should use it https://wagtailformblocks.readthedocs.io/en/latest/usage.html – allcaps Jul 09 '18 at 06:01
  • Sir, actually I was using the package ,wagtailstreamforms & I followed the instructions given in it. – divya chauhan Jul 10 '18 at 14:03

1 Answers1

0

assuming what you've put above is your actual settings:

WAGTAILSTREAMFORMS_FORM_TEMPLATES = (
    ('streamforms/form_block.html', 'Default Form Template'),
)

That is used to just populate the dropdown list of available templates within the form. What you have set is just what the default is in the settings. If you are wanting to override the default template within the package you just need to ensure the template located on the path streamforms/form_block.html in your own code is in an app that appears before wagtailstreamforms in your INSTALLED_APPS. Django will see your template first and render that.

If you want to provide an additional template to the default just have the setting:

WAGTAILSTREAMFORMS_FORM_TEMPLATES = (
    ('streamforms/form_block.html', 'Default Form Template'),
    ('example/forms/another_form_block.html', 'My Custom Template'),
)

and just create a template 'example/forms/another_form_block.html' like the example at http://wagtailstreamforms.readthedocs.io/en/latest/templates.html#templates. You will then have two choices of template to use. The one inside the package and your own.

Hope this helps.

Stuart George
  • 36
  • 1
  • 2
  • Can you please help me how to get the content of the form display.It is not rendering the fields of the forms it contains on the page.Do, I have to put this {% load streamforms_tags %} {% streamforms_form slug="form-slug" reference="some-very-unique-reference" action="." %} into my template code. – divya chauhan Jul 12 '18 at 06:04
  • how are you iterating over your stream field body in your front end template? Do you see your created forms as options to choose within your stream field? – Stuart George Jul 12 '18 at 07:11
  • Is your code public that I can look at? Have about a 100 questions – Stuart George Jul 12 '18 at 07:32
  • I edited my standard page class & put the code for my template in the above question,you can see it.Yes,I can see field form in the admin of standard page & now I even after trying with default template it is not showing the form – divya chauhan Jul 12 '18 at 09:11
  • I left the form action filed empty in the admin panel of standard page.Is it the reason – divya chauhan Jul 12 '18 at 09:22
  • I just tried your example and its working ok from here the only thin that def needs changing is the use of {{ block }} it needs to be {% include_block block %} but that will only stop csrf errors on post of the forms – Stuart George Jul 12 '18 at 12:16
  • just to confirm no u dont need {% load streamforms_tags %} {% streamforms_form slug="form-slug" reference="some-very-unique-reference" action="." %} this is for when you want your form outside a streamfield. Also the form action is only for when u need the form posted to some random url other than the page its on. – Stuart George Jul 12 '18 at 12:31
  • the only thing i can see that would answer it is that somewhere in your project there is an empty template 'streamforms/form_block.html' or similar – Stuart George Jul 12 '18 at 12:52
  • Yes, I have a template with the same name.Thanks a lot for clearing all my queries. – divya chauhan Jul 12 '18 at 13:23
  • Glad we got there :) – Stuart George Jul 12 '18 at 13:40