view.py
def login(request): username = request.POST['email'] password = request.POST['password'] print(request.POST['email']) print(request.POST['password']) user = authenticate(username=username, password=password) if (user is not None): if user.is_active(): login(user) # messages.success(request,'Добро пожаловать %S'% username) return redirect('/profile') else: print("Поля заполнены неправильно") # messages.error(request,'Неверный пароль или почта') return redirect('/singn_in') models.py
class AcountManager(BaseUserManager): def create_user(self,email,password=None): if not email: raise ValueError('User must have a valid email adress.') account=self.model( email=self.normalize_email(email), ) account.set_password(password) account.save(using=self._db) return account def create_superuser(self,email,password): account=self.create_user(email,password=password) account.is_admin= True account.save(using=self._db) return account class MyUser(AbstractBaseUser): class Meta: verbose_name_plural='Пользователи' email=EmailField(unique=True,db_index=True) username=CharField(max_length=130,blank=True) balance=IntegerField(null=True) is_admin = BooleanField(default=False) #is_active = BooleanField(default=True) USERNAME_FIELD='email' REQUIRED_FIELDS = [] objects =AcountManager() @property def is_superuser(self): return self.is_admin @property def is_staff(self): return self.is_admin def is_active(self): return True def has_perm(self,perm,obj=None): return True def has_module_perms(self,app_label): return True def get_full_name(self): # The user is identified by their email address return self.email def get_short_name(self): # The user is identified by their email address return self.email def __str__(self): # __unicode__ on Python 2 return self.email login.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Sign in</title> <style type="text/css"> #centerLayer { width: 400px; /* Ширина слоя в пикселах */ margin: 0 auto; /* Отступ слева и справа */ background: #fc0; /* Цвет фона */ } </style> </head> <body> <div id="centerLayer"> <h1>Sign in</h1> <form action="{% url 'login' %}" method="post"> {% csrf_token %} <input type="email" name="email" placeholder="E-mail *"> <input type="password" name="password" placeholder="Пароль *"> <button type="submit">Enter</button> </form> <h3><a href="{% url 'registration' %}">Or regisration</a></h3> </div> </body> </html> The situation is such that the user authentication page is entered. The entered data passes successfully:
if (user is not None): if user.is_active(): login(user) but in login (user) ----> username = request.POST ['email'] gives an error that my model does not have a method of Post. I ask for help to explain or push the output from the position.