Reputation: 3084
I've been stuck on this for a while, can't seem to fix the error. I do not use reverse()
anywhere in the 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 different alterations and namespaces, e.g. trying to use just charge
, different namespaces in urls.py etc.
When I render the book/booking/
, I get the following error:
Reverse for 'charge' not found. 'charge' is not a valid view function or pattern name.
Upvotes: 3
Views: 8171
Reputation: 6824
If you want to use URL tag on that way, you need a namespace
in your urls.py.
url(r"^book/", include("bookings.urls", namespace="bookings")),
Then you can have {% url 'bookings:charge' %}
in your template.
Upvotes: 3