Reputation: 178
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).
Upvotes: 1
Views: 1793
Reputation: 1
Update Your settings.py
File:
CRISPY_TEMPLATE_PACK
setting and get its value.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")
Adjust Your Template Code:
{{ 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.
Upvotes: 0
Reputation: 56
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')
Upvotes: 3