Hi everyone,
I struggled with this error for several days and couldn’t find a solution.
error message:
# NoReverseMatch at /search/
Reverse for 'search-results' with arguments '('good book',)' not found. 1 pattern(s) tried: ['results/\\Z']
|Request Method:|POST|
| --- | --- |
|Request URL:|http://127.0.0.1:8000/search/|
|Django Version:|5.0.6|
|Exception Type:|NoReverseMatch|
|Exception Value:|Reverse for 'search-results' with arguments '('good book',)' not found. 1 pattern(s) tried: ['results/\\Z']|
|Exception Location:|C:\Users\dady\PycharmProjects\rp-portfolio\venv\lib\site-packages\django\urls\resolvers.py, line 851, in _reverse_with_prefix|
|Raised during:|search.views.search_main|
main urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('books.urls')),
path('projects/', include('projects.urls')),
path('books/', include('books.urls')),
path('bands/', views.band_list, name='band-list'),
path('bands/<int:band_id>/', views.band_detail, name='band-detail'),
path('bands/add/', views.band_create, name='band-create'),
path('bands/<int:band_id>/change/', views.band_edit, name='band-edit'),
path('bands/<int:band_id>/delete/', views.band_del, name='band-del'),
path('about-us/', views.about),
path('songs/', views.songs_list, name='songs-list'),
path('songs/<int:song_id>/', views.song_detail, name='song-detail'),
path('songs/add/', views.song_create, name='song-create'),
path('songs/<int:song_id>/change/', views.song_edit, name='song-edit'),
path('songs/<int:song_id>/delete/', views.song_del, name='song-del'),
path('contact-us/', views.contact, name='contact'),
path('email-sent/', views.email_sent, name='sent-e'),
path('', include('search.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
search urls.py
urlpatterns = [
path('search/', views.search_main, name='search-main'),
path('results/', views.search_results, name='search-results'),
]
search views.py
from django.shortcuts import render
from django.shortcuts import redirect
from django.shortcuts import HttpResponse
from search.Tzomet_script import tzomet
def search_main(request):
if request.method == 'POST':
book_name = request.POST.get('book_name')
#results = tzomet(book_name)
results = 'good book'
print(results)
#return HttpResponse(f'{results}')
return redirect('search-results', results)
else:
return render(request, 'search/search_main.html')
def search_results(request, book_details):
return render(request, 'search/search_results.html', {'book_details': book_details})
Any help will be appreciated.