Reverse {% url %} : Reverse for ‘”‘ not found. ” is not a valid View function or schema name… here is a solution to the problem.
Reverse {% url %} : Reverse for ‘”‘ not found. ” is not a valid View function or schema name
I’ve been holding on for a while and can’t seem to fix the bug. I didn’t use reverse()
anywhere in View.
urls.py
urlpatterns = [
url(r"^book/", include("bookings.urls")),
]
bookings.urls.py
from django.conf.urls import url
from . import views
app_name = 'bookings'
urlpatterns = [
url(r'^charge/$', views.charge, name='charge'),
url(r'^booking/$', views.booking, name='booking'),
]
views.py
def booking(request):
# some code
render(request, 'bookings/template.html', {'listing': listing,})
def charge(request):
# some code
template.html
<form action="{% url 'bookings:charge' %}" method="post">
I tried all the different changes and namespaces, e.g. trying to use only charge
, different namespaces in urls.py, etc.
When I render book/booking/
, I get the following error:
Reverse for ‘charge’ not found. ‘charge’ is not a valid view function
or pattern name.
Solution
If you want to use URL tags that way, you need to have a namespace
in your urls.py.
url(r"^book/", include("bookings.urls", namespace="bookings")),
You can then include {% url 'bookings:charge' %}
in the template.