1

I use semantic-ui as template for crispy-forms. When trying to load the page it results in the following error:

TemplateSyntaxError at /forum/newpost/pqs53kqsbgsqd66pg0i60u-isjtvagbo4ii4q9/

crispy tag's template_pack argument should be in ('bootstrap', 'uni_form', 'bootstrap3', 'foundation-5')

Settings file contains entries below (among others):

  • CRISPY_TEMPLATE_PACK = 'semantic-ui'
  • INSTALLED_APPS = ('crispy_forms', 'semantic_ui')

Here is the template code from forumpost_create.html:

{% extends 'forum/layouts/forum_main.html' %}
{% load crispy_forms_tags %}
{% block content %}
<div class="ui main text container">
  <form action="" method="post" class="ui form">
    {% csrf_token %}
    {% crispy form %}
    <input type="submit" value="Save" />
  </form>
</div>
{% endblock %}

The error disappears when I use form|crispy in the template, but then the template is rendered unaffected, even when looking at the output HTML source, no changes whatsoever.

Code from forms.py

class ForumPostForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(ForumPostForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper(self)
        self.helper.layout = Layout(
            Fieldset(
                'Post body',
                'body'
            ),
            ButtonHolder(
                Submit('submit', 'Submit', css_class='ui primary button')
            )
        )

    class Meta:
        model = ForumPost
        fields = ['body']

How to make this to work? Is it because I am using semantic-ui and something needs to be done differently? (Majority of the tutorials I encounter prefer bootstrap).

4
  • 1
    I think this problem is due to internal validation of crispy forms. Try using github.com/alexey-grom/crispy-semantic-ui Commented Sep 16, 2016 at 9:23
  • This is exactly the page I followed when installing crispy. Commented Sep 16, 2016 at 10:03
  • Have you added 'semantic-ui' in INSTALLED_APPS? Commented Sep 16, 2016 at 10:22
  • Yes, I mentioned that in the initial post. Commented Sep 16, 2016 at 11:48

2 Answers 2

4

You need to add semantic-ui into CRISPY_ALLOWED_TEMPLATE_PACKS in settings file

CRISPY_ALLOWED_TEMPLATE_PACKS = ('bootstrap', 'uni_form', 'bootstrap3', 'bootstrap4', 'semantic-ui')
Sign up to request clarification or add additional context in comments.

Comments

0
  1. Update Your settings.py File:

    • Locate the CRISPY_TEMPLATE_PACK setting and get its value.
    • Additionally, ensure that extact value from above variable is included within the tuple of CRISPY_ALLOWED_TEMPLATE_PACKS like so:
    CRISPY_TEMPLATE_PACK = "Bootstrap5"
    CRISPY_ALLOWED_TEMPLATE_PACKS = ("Bootstrap5",)
    

    If there are other template packs you wish to allow, you can include them in the tuple as well:

    CRISPY_ALLOWED_TEMPLATE_PACKS = ("Bootstrap4", "Bootstrap5", "uni_form")
    
  2. Adjust Your Template Code:

    • Replace instances of {{ form|crispy }} with {% crispy form %} in your template files.

This setup ensures that your project is configured to use the Bootstrap 5 templates with django-crispy-forms, and the updated template tag is correctly rendering your forms.

1 Comment

did you use any generative AI at all in the writing of this answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.