def myregister(request): form = UserRegisterForm() if request.method == 'POST': form = UserRegisterForm(request.POST) if form.is_valid(): user = form.save() username = form.cleaned_data.get('username') email = form.cleaned_data.get('email') fname = form.cleaned_data.get('first_name') lname = form.cleaned_data.get('last_name') htmly = get_template('user/email.html') d = {'username': username} subject, from_email, to = 'Welcome', '*****@*****.**', email html_content = htmly.render(d) msg = EmailMultiAlternatives(subject, html_content, from_email, [to]) msg.attach_alternative(html_content, 'text/html') msg.send() profile = UserProfile() profile.user = user profile.fname = fname profile.lname = lname profile.save() messages.success(request, 'Your Account has been successfully created!') return redirect('login') context = {'form': form} return render(request, 'user/signup.html', context)