[Answered ]-Form validate like GenericView

2👍

You seem to have mixed up function based views and class based view. What you have attempted is a function base view. To be complete it needs to look like this

def create_user(request):
    if request.method == 'POST':
        create_user_form_ = create_User_Form(request.POST)
        if form.is_valid():
            print('valid')
            return redirect('Eapp:index')
        else:
            print('error')        

    else:
        create_user_form_ = create_User_Form()

    context = {
               'create_user_form' : create_user_form_,
    }

    return render(request, 'index.html', context)

Note that this combines your index and create user methods because they contain functionality that needs to go together.

If on the other hand you want to use a CreateView your code becomes a lot shorter

class UserCreate(CreateView):
    model = Custom_User
    form_class = create_User_Form

That’s it really. But you can add refinements.

As a side note. The standard way of naming classes in python is
CreateUserForm

👤e4c5

Leave a comment