I'm getting a NoReverseMatch error but I think my files are valid

user13302616

From my base.html:

<div id="button_container">
            <button class="button"><a href="{% url 'home' %}"> HOME </a></button>
            <button class="button"><a href="{% url 'rooms' %}"> ROOMS & SUITES </button>
            <button class="button"><a href="{% url 'roomBookingsList' %}"> ROOM BOOKINGS </button>
    </div>

Urls.py:

path('rooms/mybooking', views.roomBookingsList, name='roomBookingsList'),

Views.py:

def roomBookingsList(request):
        suiteBookingList = Suite_booking.objects.all()
        context = {
            'suiteBookingList': suiteBookingList,
        }
        return render (request, 'roomBookingsList.html', context=context)

roomBookingsList.html:

{% for suiteBookingList in suiteBookingList %}
        <li> {{ suiteBookingList }}</li>
{% endfor %}

So when I run it and click the ROOM BOOKINGS from the base.html, it will show me whatever rooms I have booked. No problem here. I also want to add an edit button here so I can update the booking if I accidentally typo the name or something.

So I added in the roomBookingsList.html:

{% for suiteBookingList in suiteBookingList %}
        <li> {{ suiteBookingList }}</li> - <a href="{% url 'edit_suite' suite.id %}">Edit</a>
{% endfor %}

Added in urls.py:

path('rooms/suite/edit/<int:suite_id>', views.edit_suite, name='edit_suite'),

Added in views.py:

def edit_suite(request, suite_id):
        if request.method == 'POST':
            suite = Suite_booking.objects.get(pk=suite_id)
            form = BookingForm(request.POST, instance=suite)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(reverse('roomBookingsList'))
        else:
            suite = Suite_booking.objects.get(pk=suite_id)
            fields = model_to_dict(suite)
            form = BookingForm(initial=fields, instance=suite)
        context = {
            'form': form,
            'type': 'edit',
        }
        return render(request, 'roomBookingsList.html', context=context)

Then I tried to run it again, and this time when I click the ROOM BOOKINGS button, it gave an error:

NoReverseMatch at /system/rooms/mybooking
    Reverse for 'edit_suite' with arguments '('',)' not found. 1 pattern(s) tried: ['system/rooms/suite/edit/(?P<suite_id>[0-9]+)$']

In the traceback there's this:

D:\ssip\hotel\system\views.py, line 59, in roomBookingsList 
    59. return render (request, 'roomBookingsList.html', context=context)

I tried searching all the files I used for the ('',) but didn't find any. I also looked over my def roomBookingsList but didn't find anything odd in it. I already tried searching the error but most answers were OP forgetting the dot or underscore when passing args.

Is it because I'm calling Suite_booking object in both the def roomBookingsList and edit_suite? What should I change here?

Sorry it's long and thank you in advance.

rjg

It seems like suite.id does not exist. Shouldn't it be suiteBookingList.id instead?

{% for suiteBookingList in suiteBookingList %}
        <li> {{ suiteBookingList }}</li> - <a href="{% url 'edit_suite' suiteBookingList.id %}">Edit</a>
{% endfor %}

And though it works, I would recommend not using the same name as your variable to iterate:

{% for suite in suiteBookingList %}
        <li> {{ suite }}</li> - <a href="{% url 'edit_suite' suite.id %}">Edit</a>
{% endfor %}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

At the time upload files from my website I'm getting this error

Getting a "not defined" error in my JavaScript code when I think it is defined

Why am i getting the error NoReverseMatch at /?

Why am I getting a Django NoReverseMatch error?

Not understanding the error I'm getting in my array

I'm getting error in my program

Getting a 422 Error on Post request, but I think my request is being sent correclty

When I extend my UIViewController I'm getting NSLayoutConstraint error

I'm getting 100% ERROR in Blaze meter when I run my JMX script which has 3 CSV data config files

I'm getting a seg fault from the following code. I think it has something to do with my function call?

why i'm getting device is not registered for apns error? i have valid certificates for development enviorment

Xcode error(I think)?

I'm getting an undefined error in my project made with React

I'm getting a segmentation fault error in my program, but it is unclear how

I'm getting this weird error when testing my code

Javascript flattening an array of arrays but I'm getting error in my for loop?

I'm getting a syntax error on my IF statement, not sure why?

I'm getting an error in "Serverless Function" in my SvelteKit Project often

I'm getting an error from the implementation of my region of interest

I'm getting an error when running my code (invalid syntax)

I'm getting an syntax error in my VHDL code near counter

I'm getting a memory leak error in my own substr function

I'm getting an out of range error on my Leetcode program

I'm getting an error when creating my own widget in Flutter

I'm getting a "Boolean Required" error in my Crystal report

Getting error "Uncaught Error: Objects are not valid as a React child", but I'm not passing objects as children

I am getting this xpath error in eclipse , i think xpath is correct(1 of 1) but why am getting error

I'm getting a gpg error

When I'm running my program I'm getting out of memory error