1
votes

urls.py

from django.urls import include, path

from .views import classroom, suppliers, teachers
urlpatterns = [
    path('', classroom.home, name='home'),

    path('suppliers/', include(([
        path('', suppliers.QuizListView.as_view(), name='quiz_list'),
        path('interests/', suppliers.SupplierTruckView.as_view(), name='supplier_trucks'),
        path('taken/', suppliers.TakenQuizListView.as_view(), name='taken_quiz_list'),
        path('quiz/<int:pk>/', suppliers.take_quiz, name='take_quiz'),
        path('quiz/edit/<int:pk>/', suppliers.edit_quiz, name='edit_quiz'),

        # teachers modules
        path('quiz/add/', suppliers.QuizCreateView.as_view(), name='quiz_add'),
        path('quiz/confirm/<int:pk>/', suppliers.QuizUpdateView.as_view(), name='quiz_change'),

        path('quiz/<int:pk>/delete/', suppliers.QuizDeleteView.as_view(),name='quiz_delete'),

        path('quiz/<int:pk>/question/add/', suppliers.question_add, name='question_add'),
        path('quiz/<int:quiz_pk>/question/<int:question_pk>/', suppliers.question_change, name='question_change'),

        path('myposts', suppliers.QuizListView1.as_view(), name='quiz_change_list'),
        path('quiz/<int:pk>/results/', suppliers.QuizResultsView.as_view(), name='truck_results'),


    ], 'classroom'), namespace='suppliers')),

views.py

class QuizUpdateView(UpdateView):
    model = Activetruck
    fields = ('name', 'subject', 'origin', 'destination','total_trucks','scheduled_date','offered_price',)
    context_object_name = 'quiz'
    template_name = 'classroom/suppliers/quiz_change_form.html'

    def get_context_data(self, **kwargs):
        kwargs['questions'] = self.get_object().questions1.annotate(answers_count=Count('answers1'))
        return super().get_context_data(**kwargs)

    def get_queryset(self):
        return self.request.user.activetruck.all()

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

when my django app try to access the undermentioned URL:

 path('quiz/confirm/<int:pk>/', suppliers.QuizUpdateView.as_view(), name='quiz_change'),

it shows NoReverseMatch error. I am unable to figure out where this is coming from. Should I add the traceback too ?

This is the template in QuizUpdateView:

    <nav aria-label="breadcrumb">
    <ol class="breadcrumb">
      <li class="breadcrumb-item"><a href="{% url 'suppliers:quiz_change_list' %}">My Quizzes</a></li>
      <li class="breadcrumb-item"><a href="{% url 'suppliers:quiz_change' activetruck.pk %}">{{ quiz.name }}</a></li>
      <li class="breadcrumb-item active" aria-current="page">Results</li>
    </ol>
  </nav>
  <h2 class="mb-3">{{ quiz.name }} Results</h2>

  <div class="card">
    <div class="card-header">
      <strong>Posted Requests For Quotes</strong>
      <span class="badge badge-pill badge-primary float-right">Least Bid: {{ quiz_score.least_bid|default_if_none:0.0 }}</span>
    </div>
    <table class="table mb-0">
      <thead>
        <tr>
          <th>supplier</th>
          <th>Date</th>
          <th>Bid Amount</th>
        </tr>
      </thead>
      <tbody>
        {% for taken_quiz in taken_quizzes %}
          <tr>
            <td>{{ taken_quiz.supplier.user.username }}</td>
            <td>{{ taken_quiz.date|naturaltime }}</td>
            <td>{{ taken_quiz.least_bid }}</td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
    <div class="card-footer text-muted">
      Total respondents: <strong>{{ total_taken_quizzes }}</strong>
    </div>
  </div>

I suppose the error is in the template file as I have already checked the code thoroughly

Traceback :

Template error: In template C:\Users\Sid\Downloads\aggregator-master\django_school\templates\base.html, error at line 0 Reverse for 'quiz_change' with arguments '('',)' not found. 1 pattern(s) tried: ['suppliers/quiz/confirm/(?P[0-9]+)/$'] 1 : {% load static %} 2 : 3 : 4 :
5 : 6 : {% block title %}Yantraksh Freight{% endblock %} 7 : 8 : 9 : 10 :

Traceback:

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py" in inner 35. response = get_response(request)

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py" in _get_response 158. response = self.process_exception_by_middleware(e, request)

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py" in _get_response 156. response = response.render()

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\response.py" in render 106. self.content = self.rendered_content

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\response.py" in rendered_content 83. content = template.render(context, self._request)

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\backends\django.py" in render 61. return self.template.render(context)

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in render 175. return self._render(context)

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in _render 167. return self.nodelist.render(context)

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in render 943. bit = node.render_annotated(context)

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in render_annotated 910. return self.render(context)

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\loader_tags.py" in render 155. return compiled_parent._render(context)

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in _render 167. return self.nodelist.render(context)

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in render 943. bit = node.render_annotated(context)

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in render_annotated 910. return self.render(context)

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\loader_tags.py" in render 67. result = block.nodelist.render(context)

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in render 943. bit = node.render_annotated(context)

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\base.py" in render_annotated 910. return self.render(context)

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\defaulttags.py" in render 447. url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\urls\base.py" in reverse 88. return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))

File "C:\Users\Sid\AppData\Local\Programs\Python\Python37\lib\site-packages\django\urls\resolvers.py" in _reverse_with_prefix 632. raise NoReverseMatch(msg)

Exception Type: NoReverseMatch at /suppliers/quiz/1/results/ Exception Value: Reverse for 'quiz_change' with arguments '('',)' not found. 1 pattern(s) tried: ['suppliers/quiz/confirm/(?P[0-9]+)/$']

2
Please show the template for the view that is giving the error.Alasdair
update the question, Please check nowRahul Sharma
That template doesn't refer to the quiz_change URL. Please show the full traceback so we can see where the error is actually coming from.Daniel Roseman
Can you please search your templates and find the one that actually is doing {% url 'quiz_change' ... %}. So far you haven't posted it so we can't help you.Daniel Roseman
@DanielRoseman Is this fine ? Please check nowRahul Sharma

2 Answers

3
votes

You don't have anything called activetruck in that view. Your context object name is quiz, which you already use on the same line; you need to be consistent.

<li class="breadcrumb-item"><a href="{% url 'suppliers:quiz_change' quiz.pk %}">{{ quiz.name }}</a></li>
0
votes
<li class="breadcrumb-item"><a href="{% url 'suppliers:quiz_change' quiz.id %}">{{ quiz.name }}</a></li>

Just change quiz.pk to quiz.id.