使用 class 基本视图面临找不到反向问题

using class base view facing a issue of reverse not found

我正在为 section.html 使用 class 基础 d 视图,我试图在表单的帮助下实现添加到购物车功能,但在单击“添加到汽车”后却显示错误

反向 'section',没有找到任何参数。尝试了 1 种模式:['(?P[0-9]+)/Sections/$']

这是我的 views.py

@method_decorator(login_required, name='dispatch')
class Sections(View):
    def post(self, request, subject_id):
        sections =request.POST.get('section')
        print(sections)
        return redirect('subjects:section')


    def get(self, request, subject_id):
        subject = get_object_or_404(Subject, pk=subject_id) # retrieve the subject 
        sections = subject.section.all() # get the sections related to the subject
        return render (request, 'sections.html',{"section_list" : sections })

我的urls.py

urlpatterns = [
    path('<int:subject_id>/Sections/', Sections.as_view(),name='section'),
]

我的section.html

    <ul class="sec">
      {% for section in section_list %}
      <div class="card col-11">
        <div class="card-header">
        {{ section.title }}
        </div>
        <div class="card-body">
          <h5 class="card-about">{{ section.about_section }}</h5> <br>
          <i class="price fas fa-rupee-sign"> {{ section.price }}</i> <br> <br>
          <i class="icon text-white fas fa-chalkboard-teacher"> {{ section.teacher }}</i> 
          <i class="icon text-white fas fa-clock"> {{ section.content_duration}}</i>
          <i class="icon text-white fas fa-tags"> {{ section.subject.name }}</i>
          <form action="#" method="POST">
            {% csrf_token %}
          <input hidden type="text" name="section" value="{{section.id}}">
          <input type="submit" class="btn btn-outline-primary" value="Add To Cart">
        </form>
        </div>
      </div>
      {% endfor %}
  </ul>

我的部分模型与另一个具有外键的模型名称主题相关联

您必须指定要重定向的 subject_id,因为路径中有 <int:subject_id>,而 get 方法需要它。

@method_decorator(login_required, name='dispatch')
class Sections(View):
    def post(self, request, subject_id):
        sections =request.POST.get('section')
        print(sections)
        return redirect('subjects:section', subject_id=subject_id)