Stack Overflow Asked by user12514433 on January 5, 2022
Hey I am trying to learn the Django crispy forms, so when I try putting/injecting the {load crispy_forms_tags %}
I get the error below
Error Message
TemplateSyntaxError at /login/
'crispy_form_tags' is not a registered tag library. Must be one of:
admin_list
admin_modify
admin_urls
cache
crispy_forms_field
crispy_forms_filters
crispy_forms_tags
crispy_forms_utils
i18n
l10n
log
static
tz
Code Below: HTML
{% load crispy_form_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0 /css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<title>Login</title>
</head>
<body>
{% crispy form %}
</body>
</html>
models.py
from django.db import models
from phonenumber_field.modelfields import PhoneNumberField
class Accounts(models.Model):
name = models.CharField(max_length=100, null=False, blank=False)
last_name = models.CharField(max_length=100,null=False, blank=False)
phone = PhoneNumberField(null=False, blank=False, unique=True)
email = models.EmailField(null=False, blank=False, unique=True)
password = models.CharField(null=False, blank=False, max_length=100)
verify_password = models.CharField(null=False, blank=False, max_length=100)
def __str__(self):
return self.name
forms.py
class UserAccount(forms.Form):
class Meta:
terms = (
('agree', 'Agree'),
('disagree', 'Disagree')
)
model = Accounts
password = forms.CharField(widget=forms.PasswordInput())
verify_password = forms.CharField(widget=forms.PasswordInput())
terms_and_conditions = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=terms)
fields = (
'name',
'last_name',
'phone',
'email',
'password',
'verify_password',
'terms_and_conditions'
)
def __init__(self, *args, **kwargs):
super().__init__(self, *args, **kwargs)
self.helper = FormHelper
self.helper.form_method = 'POST'
self.helper.layout = (
'name',
'last_name',
'phone',
'email',
'password',
'verify_password',
'terms_and_conditions',
Submit('submit', 'Submit', css_class='btn-success')
)
How can I resolve this error?
I've had this problem too, the server was running fine, then when I modified the app_tags, I get this same exact issue.
Django-crispy-forms was installed using pip install django-crispy-forms. crispy_forms was added to the settings.py INSTALLED_APPS, but the problem persists.
So, apply all savings, restart your server, if the problem persists, restart your DB, and the IDE. That resolved it for me.
https://docs.djangoproject.com/en/3.0/howto/custom-template-tags/#code-layout
Answered by Oreximena on January 5, 2022
That's because you haven't added the Crispy Form tag
in INSTALLED_APPS
in your settings. Add this 'crispy_forms'
in there and should solve the problem, e.g.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.staticfiles',
'crispy_forms',
]
add these crisp tag in your templates.html should work just fine.
{% load crispy_forms_tags %}
{% csrf_token %}
{% crispy form %}
You can see more from here
Answered by AzyCrw4282 on January 5, 2022
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP