0

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.

sandeepnegi
  • 123
  • 13
  • Where did you define `category` ? – Thierno Amadou Sow Feb 08 '22 at 04:58
  • 3
    Hint: Does `'/'` not also capture `'p/'`... – Abdul Aziz Barkat Feb 08 '22 at 05:00
  • so i have change the logic part here. you might not see the whole code. as it is too big and could have creeated unecessay confusion. Because the actual problem is with how redirection is working . everything else is good and is there in my code – sandeepnegi Feb 08 '22 at 05:03
  • @AbdulAzizBarkat i think it you are right. – sandeepnegi Feb 08 '22 at 05:07
  • can i do something like if exact url match found like ```/p``` then it should call that url. otherwise, it should go to ```/``` – sandeepnegi Feb 10 '22 at 08:07
  • @AbdulAzizBarkat hi , your hint worked well. it was the actual issue . Now i'm stuck with the problem where i have to check if there is any existing url (like ```p/```, ```login/```) matching to any of the app url then it should redirect to that otherwise it should call ```/``` this url – sandeepnegi Feb 15 '22 at 06:11

0 Answers0