【发布时间】:2020-07-24 18:40:51
【问题描述】:
嘿,我正在尝试学习 Django 脆形式,所以当我尝试放入/注入 {load crispy_forms_tags %} 时,我收到以下错误
错误信息
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
以下代码: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')
)
我该如何解决这个错误?
【问题讨论】:
标签: python html django django-crispy-forms