In short: without the avatar field in Profile, everything works fine, but django-registration does not work correctly with this field. The template displays the choice of file for avatar, however, when I log in to register, the registrar swears at an avatar that is not selected (although I choose it). In the admin junk everything works well, avatars are selected and stored.

models.py from django.db import models from django.contrib.auth.models import ( BaseUserManager, AbstractBaseUser ) class ProfileManager(BaseUserManager): def create_user(self, email, city, MyUsername, phone, first_name, last_name, address, gender, birth_date, info, avatar, password=None): if not email: raise ValueError('Users must have an email address') user = self.model( email=self.normalize_email(email), password=password, city=city, MyUsername=MyUsername, phone=phone, first_name=first_name, last_name=last_name, address=address, gender=gender, birth_date=birth_date, info=info, avatar=avatar ) user.set_password(password) user.save(using=self._db) return user def create_superuser(self, email, city, MyUsername, phone, first_name, last_name, address, gender, birth_date, info, avatar, password=None): user = self.create_user( email=self.normalize_email(email), password=password, city=city, MyUsername=MyUsername, phone=phone, first_name=first_name, last_name=last_name, address=address, gender=gender, birth_date=birth_date, info=info, avatar=avatar ) user.is_admin = True user.save(using=self._db) return user class Profile(AbstractBaseUser): email = models.EmailField( verbose_name='email address', max_length=255, unique=True, ) city = models.CharField(max_length=100) is_active = models.BooleanField(default=True) is_admin = models.BooleanField(default=False) MyUsername = models.CharField(max_length=255, unique=True) phone = models.CharField(max_length=20, null=False) first_name = models.CharField(max_length=255, null=False) last_name = models.CharField(max_length=255, null=False) address = models.CharField(max_length=255, null=False) gender = models.BooleanField(null=False) birth_date = models.DateField(null=False) info = models.TextField(null=True) avatar = models.ImageField(upload_to='avatars/', null=True) object = ProfileManager() USERNAME_FIELD = 'email' REQUIRED_FIELDS = [ 'MyUsername' ] def get_full_name(self): return self.email def get_short_name(self): return self.email def __str__(self): return self.email def has_perm(self, perm, obj=None): "Does the user have a specific permission?" return True def has_module_perms(self, app_label): "Does the user have permissions to view the app `app_label`?" return True @property def is_staff(self): """Is the user a member of staff?""" return self.is_admin 

Forms.py forms

 from registration.forms import RegistrationForm from user_registration.models import Profile class MyCustomUserForm(RegistrationForm): class Meta: model = Profile fields = [ Profile.USERNAME_FIELD, 'email', 'password1', 'password2', 'city', 'MyUsername', 'phone', 'first_name', 'last_name', 'address', 'gender', 'birth_date', 'info', 'avatar', ] 

template

 {% extends "base.html" %} {% block content %} <h1>Регистрация</h1> <form method="post" action="" enctype="multipart/form-data">{% csrf_token %} <dl class="register"> {% for field in form %} <dt>{{ field.label_tag }}</dt> <dd class="clearfix">{{ field }} {% if field.help_text %}<div class="clearfix">{{ field.help_text }}</div>{% endif %} {% if field.errors %}<div class="myerrors clearfix">{{ field.errors }}</div>{% endif %} </dd> {% endfor %} </dl> <input type="submit" value="Зарегистрироваться" / class="clearfix"> </form> {% endblock %} 
  • in which part it does not display it, I didn’t quite understand if in the template it is necessary to put a check whether there is an image, if there is a show url. - Igor
  • Well, the forms are all substituted, including the form for loading the image. I upload a picture there, but she refuses to load. PS I will attach the template code - artemyel
  • point out another error, which is issued - Igor
  • This is the latest version of jungle. The user extension is exactly what the docks of the last jung is. - artemyel

1 answer 1

 <form method="post" action="" enctype="multipart/form-data"> 

without enctype = "multipart / form-data" loading of files does not work.