user9538877
user9538877

Reputation: 198

Unable to parse the date in the url Django

I have a url like this get method in a browser it says 404 page not found error

http://localhost:8000/getup/downloadrange/ef46219d-7b33-4bdc-aab1-c3bf073dca0e/datebottom=2019-10-10&datetop=2020-10-01/

My urls.py is like this

path(
    "downloadrange/<uuid:id>/(?P<datebottom>\d{4}-\d{2}-\d{2})&(?P<datetop>\d{4}-\d{2}-\d{2})/$",
    views.getup,
    name="getup",
),

The url pattern is not found for this. Kindly help me in this regard

my views.py

def getup(request, id, dateone, datetwo):
    queryset_two = (
        getup.objects.filter(process_id=id)
        .filter(created_on__date__range=[dateone, datetwo])
        
    )
    return render_to_csv_response(qs)

Upvotes: 0

Views: 68

Answers (1)

Biplove Lamichhane
Biplove Lamichhane

Reputation: 4095

The valid url you are expecting according to your configuration is:

http://localhost:8000/getup/downloadrange/ef46219d-7b33-4bdc-aab1-c3bf073dca0e/2019-10-10&2020-10-01/

NOT

http://localhost:8000/getup/downloadrange/ef46219d-7b33-4bdc-aab1-c3bf073dca0e/datebottom=2019-10-10&datetop=2020-10-01/

Your views have that capacity to take datebottom and datetop automatically from your url if it is valid.

Edit

As you are using path, the url confs is different. So, we will change from path to re_path to support regex:

from django.urls import re_path
re_path(
    "downloadrange/(?P<id>[0-9a-f-]+)/(?P<datebottom>\d{4}-\d{2}-\d{2})&(?P<datetop>\d{4}-\d{2}-\d{2})/$",
    views.getup,
    name="getup",
),

Upvotes: 1

Related Questions