Exemplo n.º 1
0
def register(request):
    if request.FILES:
        print('file')
    if request.method == 'POST':
        userForm = UserCreationForm(request.POST)
        profileForm = ProfileForm(request.POST)
        if userForm.is_valid() and profileForm.is_valid():
            user = userForm.save()
            user.refresh_from_db()
            profileForm = ProfileForm(request.POST,
                                      request.FILES,
                                      instance=user.profile)
            profileForm.full_clean()
            profileForm.save()

            # return redirect('accounts/login.html')
            url = 'accounts/dashboard/' + str(user.username) + '/'
            return redirect('http://127.0.0.1:8000/' + url, permanent=True)
        else:
            return HttpResponse('failed')
    else:
        userForm = UserCreationForm()
        profileForm = ProfileForm()
        context = {'userForm': userForm, 'profileForm': profileForm}
        return render(request, 'accounts/signup.html', context)
Exemplo n.º 2
0
def signup(request):

    if request.method == 'POST':
        user_form = UserForm(request.POST)
        profile_form = ProfileForm(request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.refresh_from_db()
            profile_form.full_clean()
            profile_form = ProfileForm(request.POST, instance=user.profile)
            profile_form.save()
            return redirect('login')

    else:
        user_form = UserForm()
        profile_form = ProfileForm()

    return render(request, 'accounts/signup.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })