python - Passing Date to Url Tag Django -


i trying pass date url tag. here url regex:

url(r'^fund_details/?startdate=(?p<date_index>\d{2}-\d{2}-\d{4})/?offset(?p<date_offset>\d{2}-\d{2}-\d{4})/ 

and url tag:

{% url 'fund_monitor:fund_details' start_date offset %} 

but error

valueerror: invalid literal int() base 10: '08-18-2017' 

note start date '08-18-2017'. think because regex looking number rather string. however, need - in between numbers. how can achieve this?

a cleaner way of achieving intended result specifying url structure until query string, , implement logic in view function or class. practically speaking, should have following:

urls.py (or whatever filename containing url bindings):

url(r'^fund_details/$', yourviewclass.as_view(), name="url_alias") 

(note $ symbol in end - far experience concerned, should work if full url has query string in end.)

views.py or other arbitrarily-named file:

def handle_request(request):     start_date = request.get["start_date"]     date_offset = request.get["date_offset"]      # own validation acquired input     # compute output validated data 

constructing query string ?startdate=01-01-2017&offset=01-01-2016 (or rather, automatically) done using html form.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -