May-14-2023, 08:41 AM
I am trying to make a hotel reservation app with Django, but I am completely stumped why I keep getting this error
NoReverseMatch at /
Reverse for 'search_results' with keyword arguments '{'check_in_date': '', 'check_out_date': ''}' not found. 1 pattern(s) tried: ['search_results/(?P<check_in_date>[^/]+)/(?P<check_out_date>[^/]+)/\\Z']
I am basically trying to pass the check_in_date and check_out_date from the index.html input onto the next page (search_results). But I don't know how to solve this. Here is the url pattern
NoReverseMatch at /
Reverse for 'search_results' with keyword arguments '{'check_in_date': '', 'check_out_date': ''}' not found. 1 pattern(s) tried: ['search_results/(?P<check_in_date>[^/]+)/(?P<check_out_date>[^/]+)/\\Z']
I am basically trying to pass the check_in_date and check_out_date from the index.html input onto the next page (search_results). But I don't know how to solve this. Here is the url pattern
urlpatterns = [ path('', views.index, name='index'), path('search_results/<str:check_in_date>/<str:check_out_date>/', views.search_results, name='search_results'), path('make_reservation/<str:check_in_date>/<str:check_out_date>/', views.make_reservation, name='make_reservation') ]Here is the index.html file
<form method="post" action="{% url 'search_results' check_in_date=check_in_date_str check_out_date=check_out_date_str %}"> {% csrf_token %} <label for="check_in_date">Check In Date:</label> <input type="date" id="check_in_date" name="check_in_date" required> <label for="check_out_date">Check-out Date:</label> <input type="date" id="check_out_date" name="check_out_date" required> <button type="submit">Search</button> </form>Here is the view
def index(request): if request.method == 'POST': check_in_date = request.POST.get('check_in_date') check_out_date = request.POST.get('check_out_date') search_results_url = reverse('search_results', args=[check_in_date, check_out_date]) return redirect(search_results_url) return render(request, 'myapp/index.html')If anyone can tell me what I am doing wrong here, it would be much appreciated.