def forms_view(request):
    form = forms.UserForm()

    if request.method == "POST":
        form = forms.UserForm(request.POST)

        if form.is_valid():
            new_user = User(first_name=form.cleaned_data['first_name'],
                            second_name=form.cleaned_data['second_name'],
                            email=form.cleaned_data['email'])
            new_user.save()
            return home(request)

    return render(request, 'users_app/form_page.html', {'form': form})
示例#2
0
def sign_up(request):
    sign_up_form = forms.FormSignUp()

    if request.method == 'POST':
        sign_up_form = forms.FormSignUp(request.POST)

        if sign_up_form.is_valid():
            new_user = User(name=sign_up_form.cleaned_data['name'],
                            last_name=sign_up_form.cleaned_data['last_name'],
                            email=sign_up_form.cleaned_data['email'])
            new_user.save()
    return render(request,
                  'users_app/sign_up.html',
                  context={'form': sign_up_form})
示例#3
0
    def post(self, request):
        user = User(
            username=request.POST['name'],
            email=request.POST['email'],
        )

        user.save()

        context = {
            'user': user,
        }

        return render(
            template_name='form.html',
            request=request,
            context=context,
        )