John Doe
John Doe

Reputation: 1639

path : Django 2.2 path converter

I must miss something on how to work with path (not the function, the path converter). I don't understand why the None value in the following :

I have an url :

urlpatterns = [
    ...
    re_path(r'(<path:current_path>)?', views.index, name='index'),
    ...
]

A view :

def index(request, current_path):
    logger.error(f'current_path : {current_path}')
    path = request.path
    ...

Everything functions except that current_path value remains None, whatever is the given path, while request.path holds the correct value.

Why ?

Edit : I expected current_path = 'home/user' when I pass the following url : http://127.0.0.1:8080/file_system//home/user/

Upvotes: 1

Views: 256

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599956

You're using re_path in your pattern. That uses regexes rather than path converters. You should use path instead, and remove the regex parts.

path('<path:current_path>', views.index, name='index'),

Upvotes: 2

Related Questions