문제

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