Я реализовал детальный просмотр с помощью views.py сегодня днем.
У меня есть модель с pk, установленным как UUID.
соответствующая строка URL-адресов:
path('user/detail/<uuid:pk>', UserDetailView.as_view(), name='userdetail'),
ссылающийся на нее шаблон:
<a href="{% url 'userdetail' user.pk %}">
, который генерирует следующий URL:
http://127.0.0.1: 8000 / accounts / user / detail / 809b0ec2-d604-4171-8966-0817bfd59c88
, однако я получаю:
Обратное для 'userdetail' с аргументами '('',)' не найден. Пробовали 1 шаблон (ы): ['accounts / user / detail / (? P [0-9a-f] {8} - [0-9a-f] {4} - [0-9a-f] {4}] - [0-9a-f] {4} - [0-9a-f] {12}) $ '].
Если я использую имя пользователя, например, электронное письмо от пользователя AbstractBase, подробному представлению он не нравится, так как он хочет Pk или slug.
Помощь будет очень признательна.
РЕДАКТИРОВАТЬ: Я включаю модель ниже;
class UserDetails(AbstractBaseUser, PermissionsMixin):
FormFieldUserID = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
FormFieldTitle = models.CharField(max_length=75, help_text='Enter title',
verbose_name="Enter")
FormFieldFirstName = models.CharField(max_length=75, help_text='Enter First Name',
verbose_name="First Name") # Users First Name
FormFieldMiddleName = models.CharField(max_length=75, help_text='Enter Middle Name', blank=True,
verbose_name="Middle Names") # Users middle name
FormFieldLastName = models.CharField(max_length=75, help_text='Enter Last Name',
verbose_name="Last Name") # users last name
email = models.EmailField(max_length=254, unique=True, help_text="Enter Username/email",
verbose_name="Email Address") # user email
FormFieldUserImg = ResizedImageField(size=[40,40], crop=['middle', 'center'], upload_to='project/images/',
help_text="Choose project image", blank=True)
FormFieldAddr1 = models.CharField(max_length=100, help_text='Enter Address',
verbose_name="Address 1") # Users Address
FormFieldAddr2 = models.CharField(max_length=100, help_text='Enter Address', blank=True,
verbose_name="Address 2") # Users Address
FormFieldAddr3 = models.CharField(max_length=100, help_text='Enter Address', blank=True,
verbose_name="Address 3") # Users Address
FormFieldAddr4 = models.CharField(max_length=100, help_text='Enter Address', blank=True,
verbose_name="Address 4") # Users Address
FormFieldCounty = models.CharField(max_length=200, help_text='Enter County',
verbose_name="County") # Users county
FormFieldCountry = CountryField(help_text='Select user country', verbose_name="Country") # Users country
FormFieldAddrCode = models.CharField(max_length=20, help_text='Enter zip/post code',
verbose_name="Post Code") # Users Post Code
FormFieldMobileNo = models.CharField(max_length=25, help_text="Enter Mobile Phone Number",
verbose_name="Mobile Number") # User mobile Number
FormFieldPhoneNo = models.CharField(max_length=25, help_text="Enter Phone Number",
verbose_name="Phone Number",blank=True) # User phone Number
FormFieldWebAddr = models.CharField(max_length=254, help_text='Enter website details',
verbose_name="Website Details",blank=True) # User Website details
FormFieldUserNotes = models.CharField(max_length=254, help_text='Enter any user notes',
verbose_name="User Notes",blank=True) # User notes
FormFieldDateAdded = models.DateTimeField(default=datetime.now, help_text='Date user added',
verbose_name="User added date")
FormFieldAddedBy = models.CharField(default=settings.AUTH_USER_MODEL, max_length=200,
help_text='Select update detail', verbose_name="Used added by")
# Fields required by Abstract Model for users auth
is_active = models.BooleanField(default=True, help_text='Is User Active',
verbose_name="User Active") # Default must be true )
is_admin = models.BooleanField(default=False, help_text='Is user an administrator',
verbose_name="Admin User") # Default must be false)
USERNAME_FIELD = 'email'
objects = CustomUserManager()
def __str__(self):
return self.email
def has_perm(self, perm, obj=None):
"""Does the user have a specific permission?"""
# Simplest possible answer: Yes, always
return True
def has_module_perms(self, app_label):
"""Does the user have permissions to view the app `app_label`?"""
# Simplest possible answer: Yes, always
return True
@property
def is_staff(self):
"""Is the user a member of staff?"""
# Simplest possible answer: All admins are staff
return self.is_admin
class Meta:
verbose_name = 'User Detail'
verbose_name_plural = 'User Details'