{{{
url(r"^(\w+)/test1/(?P<pk>[0-9]+)/list/$", SamplesListView.as_view(),
name='list_view'),
}}}
Simple code for my view:
{{{
class SamplesListView(ListView):
model = Sample
template_name = 'samples/samples_list.html'
def get(self, request, project_name, *args, **kwargs):
print("project_name", project_name)
return super().get(self, request, project_name, *args, **kwargs)
}}}
It works ok when I pass only args or kwargs into url.
--
Ticket URL: <https://code.djangoproject.com/ticket/28587>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
Ticket URL: <https://code.djangoproject.com/ticket/28587#comment:1>
* cc: Adrian (added)
Old description:
> When I have in my urlpatterns args and kwargs the ListView is loosing
> args (it's returning empty tuple)
>
> {{{
> url(r"^(\w+)/test1/(?P<pk>[0-9]+)/list/$", SamplesListView.as_view(),
> name='list_view'),
> }}}
>
> Simple code for my view:
>
> {{{
> class SamplesListView(ListView):
> model = Sample
> template_name = 'samples/samples_list.html'
>
> def get(self, request, project_name, *args, **kwargs):
> print("project_name", project_name)
> return super().get(self, request, project_name, *args, **kwargs)
> }}}
>
> It works ok when I pass only args or kwargs into url.
New description:
When I have in my urlpatterns args and kwargs the ListView is loosing args
(it's returning empty tuple)
{{{
url(r"^(\w+)/test1/(?P<pk>[0-9]+)/list/$", SamplesListView.as_view(),
name='list_view'),
}}}
Simple code for my view:
{{{
class SamplesListView(ListView):
model = Sample
template_name = 'samples/samples_list.html'
def get(self, request, project_name, *args, **kwargs):
print("project_name", project_name)
return super().get(self, request, project_name, *args, **kwargs)
}}}
It works ok when I pass only args or kwargs into url.
THE PROBLEM occurs in ALL generic view (CreateView, UpdateView,
DeleteVIew, ListView)
--
--
Ticket URL: <https://code.djangoproject.com/ticket/28587#comment:2>
Comment (by Tim Graham):
Based on the documentation, I'm not sure if this is a bug. There's
[https://docs.djangoproject.com/en/dev/topics/http/urls/#the-matching-
grouping-algorithm a note] that says, "Here’s the algorithm the URLconf
parser follows, with respect to named groups vs. non-named groups in a
regular expression: If there are any named arguments, it will use those,
ignoring non-named arguments." which seems to be what's happening here.
The behavior isn't specific to generic views. If you use a function-based
view, you'll see the same thing.
I'm not sure the reason for that behavior and if changing it is feasible,
but it does seem unintuitive. On the other hand, is there a reason you
must mix args and kwargs in the URL pattern? Do you want to look into
writing a patch?
--
Ticket URL: <https://code.djangoproject.com/ticket/28587#comment:3>
* status: new => closed
* resolution: => invalid
--
Ticket URL: <https://code.djangoproject.com/ticket/28587#comment:4>