Opened 7 years ago
Closed 7 years ago
#28587 closed Bug (invalid)
All Generic Views are loosing args when you pass args and kwargs into urlpattern
Reported by: | Adrian | Owned by: | nobody |
---|---|---|---|
Component: | Generic views | Version: | 1.11 |
Severity: | Normal | Keywords: | ListView, CBV, generic, |
Cc: | Adrian | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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)
Change History (4)
comment:1 by , 7 years ago
Summary: | ListView cleaning ar → ListView cleaning args when you pass args and kwargs into urlpattern |
---|
comment:2 by , 7 years ago
Cc: | added |
---|---|
Description: | modified (diff) |
Summary: | ListView cleaning args when you pass args and kwargs into urlpattern → All Generic Views are loosing args when you pass args and kwargs into urlpattern |
comment:3 by , 7 years ago
comment:4 by , 7 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Based on the documentation, I'm not sure if this is a bug. There's 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?