Question

Is there any way to get keyword argument declared in url.py inside class based views methods?

For example: I want to override get_initial(self) to set one of the values to value from url. Do I really need to override __init__ to do that?

Était-ce utile?

La solution

You can do it like this:

arg_value = self.kwargs.get(ARGUMENT_NAME, None)

Which is how it is done in the SingleObjectMixin, which provides the get_object functionality used in DetailView.

https://github.com/django/django/blob/master/django/views/generic/detail.py#L34

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top