Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16595

CrispyError : as_crispy_field got passed an invalid or inexistent field for email field only

$
0
0

I can't expose Email field from User model in django, If I remove email field from register.html there is no error.Also if I use {{ form }} It does not show the email field. It shows username, password1 and password2 with no error.

models.py:

from django.contrib.auth.models import Userclass Profile(models.Model):    profile_pic = models.ImageField(null=True, blank=True, default='default.jpg')    # FK    user = models.ForeignKey(User,  max_length=10, on_delete=models.CASCADE, null=True)

forms.py:

from django.contrib.auth.models import Userclass CreateUserForm(UserCreationForm):    class Meta:        model = User        fields= ['username','email', 'password1', 'password2']

views.py:from .forms import UserCreationForm

def register(request):    form = UserCreationForm()    if request.method == "POST":       form = UserCreationForm(request.POST)       if form.is_valid():          form.save()          return redirect("my-login")    context = {'form': form}    return render(request, "register.html", context=context)

register.html

{% load static %}{% load crispy_forms_tags %}...<form action="" method="POST" autocomplete="off">{% csrf_token %}    {{ form.username|as_crispy_field }}     # error is here    {{ form.email|as_crispy_field }}    {{ form.password1|as_crispy_field }}    {{ form.password2|as_crispy_field }}<input type="submit" value="submit" /></form>

Django 4.2.10

django-bootstrap4 24.1

django-crispy-forms 1.14.0

pillow 10.2.0

wheel 0.42.0


Viewing all articles
Browse latest Browse all 16595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>