pythondjangourlconf

Urlconf does not appear to have any patterns in it


I am getting this error but I cannot figure it out. In views.py I have:

...code...
def get_success_url(self):
    booking = self.object
    return reverse("complete_booking", booking.id)

urls.py:

from django.urls import path
from . import views


urlpatterns = [
    path(
        'confirm/',
        views.ConfirmTripView.as_view(),
        name="confirm_trip"),

    path(
        '<pk>/passengers/add',
        views.InputPassengersView.as_view(),
        name="create_passengers"),

    path(
        '<pk>/checkout/',
        views.CompleteBookingView.as_view(),
        name="complete_booking"),
]

What confuses me is I have almost identical for the 'create_passengers' view (booking.id passed as argument) and it works fine.

The traceback says:

Traceback Switch to copy-and-paste view

"The included URLconf '{name}' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import."

The above exception ('int' object is not iterable) was the direct cause of the following exception: Could I get some help solving this?


Solution

  • The reason this does not work is because reverse(…) [Django-doc] takes as parameters args and kwargs. args should be an iterable of items, like a tuple, list, etc. and kwargs a dictionary-like object. You thus reverse with:

    def get_success_url(self):
        return reverse('complete_booking', args=(self.object.id,))

    redirect(…) [Django-doc] on the other hand works with positional and named parameters, but you can not use this for a get_success_url.