'Django i try to use reverse function and i got NoReverseMatch
i am a new at Django framework. and i follow of some guide on udemy and do step by step but something go wrong.
i open startapp call 'accounts', and then i have file call urls.py here is what i have.
from django.urls import path
from . import views
app_name = 'accounts'
urlpatterns = [
path("<int:month>", views.monthly_num),
path("<str:month>", views.monthly_str, name='monthly-acc'),
]
and in views.py file i want to do reverse and to do redirect.
from django.shortcuts import render
from django.http import HttpResponseNotFound
from django.http import HttpResponse, HttpResponseRedirect
from django.urls import reverse
# Create your views here.
months = {
"january": "Hello january",
"febuary": "Hello febuary",
"march": "Hello march",
"april": "Hello april", }
def monthly_str(request, month):
try:
text_month = months[month]
return HttpResponse("<h1>"+text_month+"</h1>")
except:
return HttpResponseNotFound("THIS NOT A MONTH!")
def monthly_num(request, month):
monthly = list(months.keys())
if month > len(monthly) or month <= 0:
return HttpResponseNotFound("<h1>NO GOOD</h1>")
redirect_month = monthly[month-1]
redirect_path = reverse('monthly-acc', args=[redirect_month]) # HERE I GOT THE ERROR.
return HttpResponseRedirect(redirect_path)
so what i try to do
i have the local url for example: http://mypro:9000/acc/1 i want to redirect to http://mypro:9000/acc/january
and i got this page error.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

