don't redirect correctly

hello there
need your help
i have wrote some codes to register my user by sending random code and confirm the code in seperate form and template
after all i have done i dont know why after complete and send the form the next template does’nt show up
here are my view , model and the url i got in my browser url bar
what do you think?

view.py

from django.shortcuts import render , redirect
from django.views import View
from .forms import UserRegistrationForm , VerifyCodeForm
import random
from utils import send_otp_code
from .models import OtpCode , User
from django.contrib import messages

class UserRegisterView(View):
    form_class = UserRegistrationForm
    def get(self , request):
        form = self.form_class
        return render(request , 'accounts/register.html' , {'form':form})

    def post(self , request):
        form = self.form_class(request.POST)
        if form.is_valid():
            random_code = random.randint(1000 , 9999)
            send_otp_code(phone_number= form.cleaned_data['phone_number'] , code=random_code)
            OtpCode.objects.create(phone_number = form.cleaned_data['phone_number'] , code= random_code)
            request.session['user_registration_info'] = {
                'phone_number':form.cleaned_data['phone_number'],
                'full_name':form.cleaned_data['full_name'],
                'email':form.cleaned_data['email'],
                'password':form.cleaned_data['password']
            }
            messages.success(request , 'we sent you a code !' , 'success')
            return redirect('accounts:verify_code')
        return redirect('home:home') 
    
class UserRegistrationVerifyCodeView(View):
    from_class = VerifyCodeForm
    def get(self , request):
        form = self.from_class
        return render(request , 'accounts/verify.html' , {'form':form})
    
    def post(self , request):
        user_session = request.session['user_registration_info']
        code_instance = OtpCode.objects.get(phone_number =user_session['phone_number'])
        form = self.from_class(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            if cd['code']==code_instance.code:
                User.objects.create_user(user_session['email'] , user_session['full_name'] ,
                                          user_session['phone_number'] , user_session['password'])
                code_instance.delete()
                messages.success(request , 'you registred' , 'success')
                return redirect('home:home')
            else:
                messages.error(request , 'code doesnt match' , 'danger')
                return redirect('accounts:verify_code')
        return redirect('home:home')
    

model.py

from django.db import models
from django.contrib.auth.models import AbstractBaseUser
from .managers import UserManager


class User(AbstractBaseUser):
    email = models.EmailField(max_length=255 , unique=True)
    full_name = models.CharField(max_length=100)
    phone_number = models.CharField(max_length=11 , unique=True)
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)

    objects = UserManager()

    USERNAME_FIELD = 'phone_number'
    REQUIRED_FIELDS = ['email' , 'full_name']

    def __str__(self) -> str:
        return self.email
    
    def has_perm(self , perm , obj=None):
        return True
    
    def has_module_perms(self , app_label):
        return True
    
    def is_staff(self):
        return self.is_admin

class OtpCode(models.Model):
    phone_number = models.CharField(max_length=11)
    code = models.PositiveSmallIntegerField()
    created = models.DateTimeField(auto_now=True)

    def __str__(self) -> str:
        return f'{self.phone_number}  - {self.code} - {self.created}'

the url i get instead of redirecting to next template

[type or paste code here](http://127.0.0.1:8000/accounts/register/?csrfmiddlewaretoken=BQI2MOXOsD4UYY7JlnfEHdEMFPZG2i8MaJ9L3b6lzXeZXoLTBzM5FdnLYrdCIlXW&email=leon%40email.com&phone_number=12345678910&full_name=leon+k+&password=leon)

You wrote:

You’ve identified what doesn’t happen. What does happen?

What is the send_otp_code function?

You’re not handling the case where the form is not valid in your UserRegisterView. Also, since you are processing a form here, you really should be building this on the FormView class and not View.

Please post your urls.py files (both your project level file and your app file).

Also please post your UserRegistrationForm and VerifyCodeForm forms, along with the accounts/register.html and accounts:verify_code.html templates.

my app urls.py

from django.urls import path
from . import views
app_name = 'accounts'

urlpatterns = [
    path('register/' , views.UserRegisterView.as_view() , name='user_register'),
    path('verify/' , views.UserRegistrationVerifyCodeView.as_view() , name= 'verify_code')
]

my proj urls.py


from django.contrib import admin
from django.urls import path , include


urlpatterns = [
    path('admin/', admin.site.urls),
    path('' , include('home.urls' , namespace='home')),
    path('accounts/' , include('accounts.urls' ,namespace='accounts' ))
]

my UserRegistrationForm

class UserRegistrationForm(forms.Form):
    email = forms.EmailField()
    phone_number = forms.CharField(max_length=11)
    full_name = forms.CharField(max_length=100 , label='full name')
    password = forms.CharField(widget=forms.PasswordInput)

my VerifyCodeForm

class VerifyCodeForm(forms.Form):
    code = forms.IntegerField()

register.html

{% extends 'base.html' %}
{% block content %}
<form action="" method="post">
    {% csrf_token %}
    {{form.as_p}}
    <input type="submit" value="Send">
</form>
{% endblock %}

verify_code.html

{% extends 'base.html' %}
{% block content %}
<form action="" method="post">
    {% csrf_token %}
    {{form.as_p}}
    <input type="submit" value="verify">
</form>
{% endblock %}

I think you should have instantiated the forms like this: form = self.form_class()

registration form load correctly in register page but after filling up the form next template wont appear
thanks for your answer but it’s not the solution

To ask again: What does appear? What happens when you submit the form?

And, You’re not handling the case where the form is not valid in your UserRegisterView. You should be returning the current form, rendered with the errors being displayed.

(Also, since you are processing a form here, you really should be building this on the FormView class and not View.)