コード例 #1
0
ファイル: views.py プロジェクト: Mlock/superfriends
def sign_up(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save()

            # Log-in the user right away, then redirect home
            messages.success(request, 'Account created successfully. Welcome!')
            login(request, user)
            return redirect('home')
    else:
        form = SignupForm()

    context = {
        'form': form,
    }
    return render(request, 'accounts/signup.html', context)
コード例 #2
0
ファイル: views.py プロジェクト: amulifts/Blog-app
    def post(self, request):
        if request.method == "POST":
            form = SignupForm(request.POST)
            if form.is_valid():
                user = form.save(commit=False)
                print(form.cleaned_data)
                username = form.cleaned_data["username"]
                raw_password = form.cleaned_data["password1"]
                user.save()
                user = authenticate(username=username, password=raw_password)
                if user:
                    login(request, user)
                return redirect("success")
            else:
                print(form.errors)
                return render(request, self.template_name, {"form": form})

        else:
            return render(request, self.template_name, {"form": self.form})
コード例 #3
0
ファイル: views.py プロジェクト: kroefeet/quiet_share
def sign_up(request):
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            password = forms.CharField(widget=forms.PasswordInput)
            user.set_password(form.cleaned_data['password'])
            user.save()

            # Log-in the user right away
            messages.success(request, 'Account created successfully. Welcome!')
            login(request, user)
            return redirect('/')
    else:
        form = SignupForm()

    context = {
        'form': form,
    }
    return render(request, 'accounts/signup.html', context)