gpt4 book ai didi

NoReverseMatch at /applicant-dependant-update/2/ Reverse for 'applicants' with keyword arguments '{'pk': 2}' not found. 1 pattern(s) tried: ['\\Z'](找不到关键字参数为‘{’pk‘:2}’的‘申请者’的NoReverseMatch at/Applicant-Dependant-UPDATE/2/Reverse。1模式(S)已尝试:[‘\\Z’])

转载 作者:bug小助手 更新时间:2023-10-25 17:25:36 24 4
gpt4 key购买 nike



I am trying to create a form where parent and child relationships can be handled in one form through inlineformset, when i try to update the applicant, or add another one, i keep getting noReverseMatch error. Kindly help am new to inlineformset

我正在尝试创建一个表单,其中父子关系可以通过inlineformset在一个表单中处理,当我尝试更新申请者或添加另一个申请者时,我总是收到noReverseMatch错误。我是内联表单集的新手,请帮忙


NoReverseMatch at /applicant-dependant-update/2/
Reverse for 'applicants' with keyword arguments '{'pk': 2}' not found. 1 pattern(s) tried: ['\\Z']

Error message

错误讯息


NoReverseMatch at /applicant-dependant-update/2/
Reverse for 'applicants' with keyword arguments '{'pk': 2}' not found. 1 pattern(s) tried: ['\\Z']

Error message

错误讯息


Models.py

Models.py


class Applicant(models.Model):
application_number = models.IntegerField(null=False, blank=False, unique=True)
region = models.CharField(max_length=20, choices=REGION_CHOICES)
family_name = models.CharField(null=False, blank=False, max_length=255)
first_name = models.CharField(null=False, blank=False, max_length=255)
middle_name = models.CharField(blank=True, max_length=255)
gender = models.CharField(max_length=10, null=False, choices=GENDER_CHOICES)
month_B = models.CharField(null=False, choices=MONTH_CHOICES, max_length=100)
day_B = models.PositiveIntegerField(blank=False, null=False)
year_B = models.PositiveIntegerField(blank=False, null=False)
birth_city = models.CharField(max_length=255, null=False)
birth_country = models.CharField(max_length=255, null=False)


class Dependant(models.Model):
main_applicant = models.ForeignKey('Applicant', blank=False, null=False, on_delete=models.CASCADE,related_name='applicant_dependant')
dress_color = models.CharField(blank=True, max_length=50)
family_name = models.CharField(null=False, blank=False, max_length=255)
first_name = models.CharField(null=False, blank=False, max_length=255)
middle_name = models.CharField(blank=True, max_length=255)
gender = models.CharField(max_length=100, choices=GENDER_CHOICES)
month_B = models.CharField(blank=False, choices=MONTH_CHOICES, max_length=100)
day_B = models.PositiveIntegerField(blank=False)
year_B = models.PositiveIntegerField(blank=False)
birth_city = models.CharField(max_length=255)
birth_country = models.CharField(max_length=255)

Urls.py

Urls.py


urlpatterns = [
path('login/', UserLogin.as_view(), name='login'),
path('logout/', LogoutView.as_view(next_page='login'), name='logout'),
path('register/', RegisterPage.as_view(), name='register'),
path('', TaskList.as_view(), name='tasks' ),
path('task/<int:pk>/', TaskDetail.as_view(), name='task' ),
path('create-task/', TaskCreate.as_view(), name='create-task'),
path('update-task/<int:pk>/', TaskUpdate.as_view(), name='update-task'),
path('delete-task/<int:pk>/', TaskDelete.as_view(), name='delete-task'),
]

Views.py

Views.py


class ApplicantDependantUpdate(SingleObjectMixin, FormView):

model = Applicant
template_name = 'dataentry/applicant_dependant_update.html'

def get(self, request, *args, **kwargs):
self.object = self.get_object(queryset=Applicant.objects.all())
return super().get(request, *args, **kwargs)

def post(self, request, *args, **kwargs):
if not request.user.is_authenticated:
return HttpResponseForbidden()
self.object = self.get_object(queryset=Applicant.objects.all())
return super().post(request, *args, **kwargs)

def get_form(self, form_class = None):
return ApplicantDependantFormset(**self.get_form_kwargs(), instance=self.object)

def form_valid(self, form):
form.save(commit=False)

messages.add_message(
self.request,
messages.SUCCESS,
'Changes were saved'
)

return HttpResponseRedirect(self.get_success_url())

def get_success_url(self):
return reverse('applicants', kwargs={'pk': self.object.pk})

template

模板


{% block content %}

<form action="" method="post" enctype="multipart/form-data">
{% for hidden_field in form.hidden_fields %}
{{ hidden_field.errors }}
{{ hidden_field }}
{% endfor %}

{% csrf_token %}

{{ form.management_form }}
{{ form.non_form_errors }}

<h3>Update Applicant Dependant Information</h3>
{% for Dependant_form in form.forms %}
<hr>
<h5>
{% if Dependant_form.instance.id %}
Dependant: {{ Dependant_form.instance.family_name }}
{% else %}

{% if form.forms|length > 1 %}
Add another Dependant
{% else %}
Add Dependant
{% endif %}

{% endif %}
</h5>

{% for hidden_field in Dependant_form.hidden_fields %}
{{ hidden_field.errors }}
{% endfor %}
<!-- {{ Dependant_form.dress_color|as_crispy_field }} CAN STAND ALONE AND BE FORMATED IN DIV-->
<table>
{{ Dependant_form.as_table }}
</table>
{% endfor %}
<hr>
<p>
<button type="submit" value="Update Applicant" class="text-white bg-gradient-to-br from-green-400 to-blue-600 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-green-200 dark:focus:ring-green-800 font-medium rounded-lg text-sm px-5 py-2.5 text-center mr-2 mb-2">Submit Dependant
</button>
<a href="{% url 'applicants' %}">Cancel</a>
</p>


</form>

更多回答
优秀答案推荐
更多回答

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com