请不要客气。我目前正面临这个问题,试图在提交表单后重定向到上一页
** NoReverseMatch位于/studentportal/8/result/resultcreate/ 未找到任何参数的“student_result”则相反。尝试了1个模式:[“studentportal/(?P[0-9]+)/result/$”] **
Views.py
class ResultCreateView(CreateView ):
template_name = 'studentportal/result_create.html'
form_class = ResultModelForm
queryset = StudentResult.objects.all()
model = StudentResult
def form_valid(self, form):
print(form.cleaned_data)
return super().form_valid(form)
def get_success_url(self):
return HttpResponseRedirect(reverse('studentportal:student_result'))
url.py
app_name = 'studentportal'
urlpatterns = [
path('student_list', StudentListView.as_view(), name='student_list'),
path('<int:pk>/', StudentDetailView.as_view(), name='student_detail'),
path('create/', StudentCreateView.as_view(), name='student_create'),
path('<int:pk>/update/', StudentUpdateView.as_view(), name='student_update'),
path('<int:pk>/delete/', StudentDeleteView.as_view(), name='student_delete'),
path('<int:pk>/result/', StudentResultView.as_view(), name='student_result'),
path('<int:pk>/result/resultcreate/', ResultCreateView.as_view(), name='result_create'),
]
模板html
<form method="POST" action=" ">
{% csrf_token %}
{{ form|crispy }}
<button class="regBtn">Submit</button>
<form/>
发生这种情况是因为路径中有
pk
arg,据我所知,创建时不需要它。因此,只需将路径更改为:甚至我也会把它简化为
相关问题 更多 >
编程相关推荐