[英]Why am I getting No module named 'django.utils.lru_cache' error?
I am working a Django project.我正在做一个 Django 项目。 I have created a form and tried to use Crispy-forms to style the form.
我创建了一个表单并尝试使用 Crispy-forms 来设置表单样式。 However, when I runserver I get the following error.
但是,当我运行服务器时,出现以下错误。
File "D:\Django_Project\venv\lib\site-packages\django\template\backends\django.py", line 131, in get_package_libraries文件“D:\Django_Project\venv\lib\site-packages\django\template\backends\django.py”,第 131 行,在 get_package_libraries
raise InvalidTemplateLibrary(django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to 'crispy_forms.templatetags.crispy_forms_field': No module named 'django.utils.lru_cache'引发 InvalidTemplateLibrary(django.template.library.InvalidTemplateLibrary:指定的模板库无效。尝试“crispy_forms.templatetags.crispy_forms_field”时引发 ImportError:没有名为“django.utils.lru_cache”的模块
This is the template where I am using crispy-forms这是我使用crispy-forms的模板
{% load crispy_forms_filters %}
{% load crispy_forms_tags %}
{% block content %}
<div class="content-section">
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Join Today</legend>
{{ form |crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Sign Up</button>
</div>
</form>
<div class="border-top pt-3">
<small class="text-muted">
Already Have An Account? <a class="ml-2" href="#">Sign In</a>
</small>
</div>
</div>
{% endblock content %}```
I am using Django==4.0.6
Crispy-form==1.14.0
Have searched online for possible fix unsuccessfully. Please I need help.
I found an alternative hard coding with bootstrap since I couldn't find anyway to style using crispy-forms ''' from django import forms from django.contrib.auth.models import User from django.contrib.auth.forms import UserCreationForm I found an alternative hard coding with bootstrap since I couldn't find anyway to style using crispy-forms ''' from django import forms from django.contrib.auth.models import User from django.contrib.auth.forms import UserCreationForm
class UserRegisterForm(UserCreationForm): email = forms.EmailField(widget=forms.EmailInput(attrs={'class': 'form-control'})) first_name = forms.CharField(max_length=50, widget=forms.TextInput(attrs={'class': 'form-control'})) last_name = forms.CharField(max_length=50, widget=forms.TextInput(attrs={'class': 'form-control'})) class UserRegisterForm(UserCreationForm): email = forms.EmailField(widget=forms.EmailInput(attrs={'class': 'form-control'})) first_name = forms.CharField(max_length=50, widget=forms.TextInput(attrs ={'class': 'form-control'})) last_name = forms.CharField(max_length=50, widget=forms.TextInput(attrs={'class': 'form-control'}))
class Meta:
model = User
fields = ['username', 'first_name', 'last_name', 'email', 'password1', 'password2']
def __init__(self, *args, **kwargs):
super(UserRegisterForm, self).__init__(*args, **kwargs)
self.fields['username'].widget.attrs['class'] = 'form-control'
self.fields['password1'].widget.attrs['class'] = 'form-control'
self.fields['password2'].widget.attrs['class'] = 'form-control'
''' '''
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.