Example #1
0
def profile_view(request):
    if request.session["username"]:
        a = Register.objects.get(username=request.session["username"])

        try:
            b = Profile.objects.get(user=a)
        except:
            b = Profile(user=a)
            b.save()
            b = Profile.objects.get(user=a)

        return render(request, "blogapp/profile_view.html", {"profile": b})
    else:
        return HttpResponseRedirect("/login/")
Example #2
0
def profile_view(request):
    if request.session['username']:
        a = Register.objects.get(username=request.session['username'])

        try:
            b=Profile.objects.get(user=a)
        except:
            b=Profile(user=a)
            b.save()
            b=Profile.objects.get(user=a)

        return render(request,'blogapp/profile_view.html',{'profile':b})
    else:
        return HttpResponseRedirect('/login/')
Example #3
0
def profile(request):
    if request.session["username"]:
        if request.method == "POST":
            a = Register.objects.get(username=request.session["username"])
            # Finding the column of data of the user logged in
            try:
                b = Profile.objects.get(user=a)
                # Accessing the profile column of the user logged in if the profile exists it loads it
            except:
                b = Profile(user=a)  # A new Profile is creaed if the profile does not exist.
                b.save()
                b = Profile.objects.get(user=a)

            form = ProfileForm(request.POST, instance=b)

            if form.is_valid():
                form.save()
                return HttpResponseRedirect("/login/")
            else:
                return render(request, "blogapp/profile.html", {"form": form})
        else:
            # if the method is not POST
            a = Register.objects.get(username=request.session["username"])

            try:
                b = Profile.objects.get(user=a)
            except:
                b = Profile(user=a)
                b.save()
                b = Profile.objects.get(user=a)

            form = ProfileForm(instance=b)
            return render(request, "blogapp/profile.html", {"form": form})

    else:
        return HttpResponseRedirect("/login/")