project urls.py
urlpatterns = [
path('', include('products.urls')),
]
application urls.py
path('p/a/s/',views.get_product_store_data,name='get_product_store_data'),
# store by url
path('<str:store_url>/',views.store_from_url, name="store_from_url"),
path('p/',views.show_product_list, name="show_product_list"),
# Random store detail
path('s/d/<store_id>/',views.random_store_detail, name="random_store_detail"),
# Random Service List
path('sr/',views.get_random_service_list, name="get_random_service_list"),
in application urls.py the 2nd url is http://127.0.0.1:8000/expert-elektronikfachhandel
which take me to the store detail page
I'm calling the 1st url with the below function
def get_product_store_data(request):
"""
get all product list and store list for search text
"""
try:
if request.method == 'GET':
if category == 'all':
data = logic.get_product_store_data(request)
return render(request, 'list_product_and_store.html', data)
elif category == 'stores':
return HttpResponseRedirect(f"/s/?s={request.session['search_text']}")
elif category == 'services':
return HttpResponseRedirect(f"/sr/?s={request.session['search_text']}")
elif category == 'products':
return HttpResponseRedirect(f"/p/?s={request.session['search_text']}&p=0")
elif category == 'events':
return redirect("all_events")
elif category == 'restaurants':
return redirect("restaurant")
elif category == 'public_service':
return redirect("public_service", -1)
except Exception as e:
logger.error(f'{repr(e)} -->{request.user.username}')
return redirect("error404")
now the problem is when i call the 2nd url then it is calling the 1st url throws an error(both are in same page). Why this is happening i'm not able to find out. Is there anything which i'm doing wrong.
Ok I think i find out the problem. But I don't know how to handle this.
the 1st and 2nd url both are called with get request and from same page(this is, from home page) but the 1st url is called from a form submit (it must be a get request) and 2nd url is called when we explicitly change the url.
So when i submit the form it calls the 1st url as it is a get request and it also call the 2nd url as well. I think so? I;m not sure whether i'm thinking right or not.