Вопрос

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?

Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top