This may be a rookie mistake but it has been bugging me for days now
I am trying to create a system in which after my registration is completed a profile is automatically made and saved for the user. I have applied all my current knowledge but the following error keeps showing up.
IntegrityError at /register/ NOT NULL constraint failed: users_profile.standard
Request Method:POST
This is my views.py -
`from django.shortcuts import render, redirect
from django.contrib import messages
from .form import UserRegisterForm
from django.contrib.auth.decorators import login_required
def register(request):
if request.method == 'POST':
form = UserRegisterForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
messages.success(
request, f'Your account has been created. You are now able to log in!')
return redirect('login')
else:
form = UserRegisterForm()
return render(request, 'users/register.html', {'form': form})
@login_required
def profile(request):
return render(request, 'users/profile.html')
and my signals.py -
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from django.dispatch import receiver
from .models import Profile
@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
@receiver(post_save, sender=User)
def save_profile(sender, instance, **kwargs):
instance.profile.save()
Please help me out here guys, I am desperate.
Aucun commentaire:
Enregistrer un commentaire