from django.shortcuts import render from uuid import uuid1 from AuthApp.models import * from django.contrib import auth from django.http import HttpResponse, Http404, JsonResponse from django.template import loader, RequestContext from django.contrib.auth.decorators import login_required from BaseModels.mailSender import techSendMail from django.utils.translation import gettext as _ from datetime import datetime from django.template.loader import render_to_string def registration_ajax(request): if request.method != 'POST': raise Http404 try: data = request.POST from .forms import RegistrationForm form = RegistrationForm(data) if not form.is_valid(): Dict = {'form': form} html = render_to_string('forms/f_registration.html', Dict) return JsonResponse({'html': html}, status=400) user = User.objects.create_user(username=form.data['email'], email=form.data['email'], password=form.data['password']) # user = auth.authenticate(username=new_user_Dict['name'], password=new_user_Dict['pass']) if user: auth.login(request, user) res_Dict = {} JsonResponse(res_Dict) except Exception as e: errors_Dict = { 'errors': { '__all__': f'ошибка в запросе = {str(e)}' } } Dict = {'form': errors_Dict} html = render_to_string('forms/f_registration.html', Dict) return JsonResponse({'html': html}, status=400)