Django - two different urls calling same method which throws error

76
April 16, 2022, at 11:50 AM

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.

Rent Charter Buses Company
READ ALSO
How can I read output from multiple Linux commands as input streams in a Python script

How can I read output from multiple Linux commands as input streams in a Python script

I'm trying to write a Python program that takes 2 very large files as inputThey are both currently compressed on disk in

91
Python Selenium on Chrome | find active element name

Python Selenium on Chrome | find active element name

I’m trying to get the name of the active element through selenium

84
Apache Beam Streaming from Kafka into Files over Fixed Window not working

Apache Beam Streaming from Kafka into Files over Fixed Window not working

In python, I am trying to have a streaming pipeline that ingests data from Kafka, and then writes that data in 30 second intervals into a file at the end of each intervalI am using the FlinkRunner

124
Writing to a file with mode &quot;w&quot; versus &quot;a&quot; - I can&#39;t get &quot;w&quot; to work properly

Writing to a file with mode "w" versus "a" - I can't get "w" to work properly

Let me start out by saying I am very new to PythonI'm taking a Udemy bootcamp, so I am not by any means condoning my solution as the best solution, but for the life of me, I cannot figure out why, when I write to the output files, I have to use mode "a"...

90