1

I have the following URL config in my Django project:

urlpatterns = [
    path('', views.record_create),
    path('<entry_method>/', views.record_create, name = "record_create"),
]

The view goes:

def record_create(request, entry_method="bulk/"):

In my template I do:

<a href="{% url "record_create" entry_method=request.path_info %}">

And I get the following error:

django.urls.exceptions.NoReverseMatch: Reverse for 'record_create' with keyword arguments '{'entry_method': '/bulk/'}' not found. 1 pattern(s) tried: ['(?P<entry_method>[^/]+)/$']

Not sure what I'm doing wrong. Any suggestions are welcome.

1 Answer 1

1

The problem is not in the reverse lookup. The problem is that your entry_method in the url patterns, is by default a str path converter, not a path. You can set the type of the parameter with:

urlpatterns = [
    path('', views.record_create),
    path('<path:entry_method>', views.record_create, name = "record_create"),
]

For more information, see the documentation on Path converters [Django-doc].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.