0

我需要一些帮助。

我可以将我的问题描述为我在标题中的表现的最佳方式,但我得到了一个反向匹配错误。任何人都可以解释为什么我会遇到这个问题。这是我的代码。

# model code 

from django.core.validators import RegexValidator
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.urls import reverse 

 class CustomUser(AbstractUser):
    position = models.CharField(max_length=30, null=True )   
    email = models.EmailField(null=True, blank=False, unique=True )
    phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.")
    mobile_phone = models.CharField(validators=[phone_regex], max_length=17, blank=False, null=True, unique=True)
    date_created = models.DateTimeField(auto_now_add=True, editable=True)

     def __str__(self):
         return self.username

     def get_absolute_url(self):
         return reverse("customuser_detail", args=[str(self.id)])

     class Meta:
        ordering = ["username"] 
# view code
from accounts.models import CustomUser

from .forms import CustomUserCreationForm
from django.urls import reverse_lazy
from django.views.generic import ListView, DetailView, TemplateView
from django.views.generic.edit import CreateView,

 class CustomUserListView(ListView):
    model = CustomUser
    context_object_name = 'object_customuser_list'
    template_name = 'accounts/user_profiles/customuser_list.html'
    paginate_by = 25
    fields = '__all__'
    ordering = ('first_name','last_name')
 
class CustomUserDetailView(DetailView):
    model = CustomUser
    context_object_name = 'object_customuser_detail'
    template_name = 'accounts/userprofiles/customuser_detail.html'
#urls
 path('new_user/', views.CustomUserCreateView.as_view() , name='customuser_create'),
 path('profiles/list', views.CustomUserListView.as_view() , name='customuser_list'),
 path('profiles/details', views.CustomUserDetailView.as_view() , name='customuser_detail'),
# template: 
 {% extends 'base.html' %}

{% block content %} 
<div class="container">
    <div class="card">
        <div class="card-header">
             User Profile Listing
        </div>
        <div class="ibox-content">

            <table class="table table-hover">
                <thead>
                    <tr>
                      <th scope="col">User Name </th>
                      <th scope="col">First Name </th>
                      <th scope="col">Last Name</th>
                      <th scope="col">Email Address</th>
                      <th scope="col">Position</th>
                      <th scope="col">Is Staff</th>
                      <th scope="col">Mobile Number</th>
                      <th scope="col">Is Active</th>
                      <th scope="col">ID</th>
                    </tr>
                  </thead>
                <tbody>

                    {% for obj in object_customuser_list %}                                               
                        <tr>    
                               <td style="text-align:center"> <a  href="{% url 'customuser_detail' obj.id %}" class="search-link">{{ obj.username }}</a> </td>
                            <td> <a>{{ obj.first_name }}</a> </td>
                            <td> <a>{{ obj.last_name }}</a> </td>
                            <td> <a>{{ obj.email }}</a> </td>
                            <td> <a>{{ obj.position }}</a> </td>
                            <td> <a>{{ obj.is_staff }}</a> </td>
                            <td> <a>{{ obj.mobile }}</a> </td>  
                            <td> <a>{{ obj.is_active }}</a> </td>  
                            <td> <a>{{ obj.id }}</a> </td>   
                        </tr>
                    {% empty %}
                        <tr>
                            <td> NO RECORDS TO DISPLAY </td>
                        </tr>
                    {% endfor %}

                </tbody>
            </table>
            
            <!-- https://stackoverflow.com/questions/2603700/how-to-align-3-divs-left-center-right-inside-another-div -->
                <div class="pull-left"><a class="btn btn-primary btn-xs" href="{% url 'customuser_create' %}" role="button">New User</a> </div>
                <div class="pull-right"> {% include "includes/pagination.html" with page=page_obj %} </div> 
                <!-- pagenation is taken from the django docs -->

        </div>
    </div>  
</div>

任何帮助将不胜感激。我还包括错误消息。 错误信息

4

0 回答 0