I’m having trouble with my Django URL patterns. The URL exercise4/1/ is not matching any of my defined patterns, even though I have a pattern defined for exercise4/int:month/. Can you help me figure out why it’s not matching?”
from django.shortcuts import render
from django.http import HttpResponseNotFound,HttpResponse,HttpResponseRedirect
month_chalenge = {
'JAN': 'IT IS NEW YEAR CONGRATS',
'FEB' : 'WELCOME TO NEW MONTH OF FEBURARY',
'APRIL': 'FASTING MONTH',
'MAY': 'EDEPENDENCE DAY'
}
def month_chalenge_bynumber (request,month):
months = list( month_chalenge.keys())
redirect_month = months[month-1]
return HttpResponseRedirect(“/exercise4/”+ redirect_month)
def monthchalenge(request,month):
try:
chalenge_list = month_chalenge[month]
return HttpResponse(chalenge_list)
except:
return HttpResponseNotFound(‘sorry ! we dont have data for this data’)
Mussie Kelati is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.