Solution 1 :

Try using below code:

from django.shortcuts import render,HttpResponse
from basicapp.forms import UserForm,UserProfileInfoform


# Create your views here.
def index(request):
    return render(request,'basicapp/index.html')
def register(request):
    registered = False

    if request.method == "POST":
        user_form = UserForm(data = request.POST)
        profile_form = UserProfileInfoform(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit= False)
            profile.user = user

            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']

                profile.save()

                registered = True
            else:
                print(user_form.errors,profile_form.errors)
        else:
            user_form = UserForm()
            profile_form = UserProfileInfoform()

    return render(request,'basicapp/registration.html',
                              {'user_form':user_form,
                               'profile_form':profile_form,
                               'registered':registered})

Problem :

from django.shortcuts import render,HttpResponse
from basicapp.forms import UserForm,UserProfileInfoform


# Create your views here.
def index(request):
    return render(request,'basicapp/index.html')
def register(request):
    registered = False

    if request.method == "POST":
        user_form = UserForm(data = request.POST)
        profile_form = UserProfileInfoform(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit= False)
            profile.user = user

            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']

                profile.save()

                registered = True
            else:
                print(user_form.errors,profile_form.errors)
        else:
            user_form = UserForm()
            profile_form = UserProfileInfoform()

        return render(request,'basicapp/registration.html',
                              {'user_form':user_form,
                               'profile_form':profile_form,
                               'registered':registered})

Comments

Comment posted by user1558604

What is your question? Also fix the code formatting

Comment posted by Aryan Bagwe

views aren’t returning http response for the templates

By

Leave a Reply

Your email address will not be published. Required fields are marked *