W
W
windf1n2019-02-26 15:47:51
Django
windf1n, 2019-02-26 15:47:51

Error when entering the page, how to solve?

I welcome everyone! There was a problem. When I go to the registration page, django throws an error.
Django suggests that the error is somewhere here:
in views, what django emphasizes is highlighted:

class UserProfileManager(BaseUserManager):
    def _create_user(self, username, email, password,
                     is_superuser, **extra_fields):
        now = timezone.now()
        if not username:
            raise ValueError(_('Имя пользователя должно быть установлено'))
        email = self.normalize_email(email)
        user = self.model(username=username, email=email,
                          is_active=True,
                          is_superuser=is_superuser, last_login=now,
                          date_joined=now, **extra_fields)
        user.set_password(password)
        user.save()
        return user

    def create_user(self, username, email=None, password=None, **extra_fields):
        return self._create_user(username, email, password, False,
                                 **extra_fields)

    def create_superuser(self, username, email, password, **extra_fields):
        return self._create_user(username, email, password, True,
                                 **extra_fields)

    def get_user_by_b64username(self, b64username):
        try:
            return self.get(username=urlsafe_base64_decode(force_text(b64username)))
        except:
            raise Http404

    def get_main_admin(self):
        return self.filter(is_superuser=True).order_by('pk')[0]

and in the models, what django emphasizes is highlighted:
class UserProfileManager(BaseUserManager):
    def _create_user(self, username, email, password,
                     is_superuser, **extra_fields):
        now = timezone.now()
        if not username:
            raise ValueError(_('Имя пользователя должно быть установлено'))
        email = self.normalize_email(email)
        user = self.model(username=username, email=email,
                          is_active=True,
                          is_superuser=is_superuser, last_login=now,
                          date_joined=now, **extra_fields)
        user.set_password(password)
        user.save()
        return user

    def create_user(self, username, email=None, password=None, **extra_fields):
        return self._create_user(username, email, password, False,
                                 **extra_fields)

    def create_superuser(self, username, email, password, **extra_fields):
        return self._create_user(username, email, password, True,
                                 **extra_fields)

    def get_user_by_b64username(self, b64username):
        try:
            return self.get(username=urlsafe_base64_decode(force_text(b64username)))
        except:
            raise Http404

    def get_main_admin(self):
        return self.filter(is_superuser=True).order_by('pk')[0]

error:
5c7534e745b8c101423330.png
5c7539661e915832241444.png
5c75397000ae5849886860.png
django 1.7.1
python 3.4.1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DDDsa, 2019-02-26
@windf1n

Probably instead of
necessary
In general, the problem is that you most likely do not have a single superuser yet.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question