Автор Тема: Generic detail view Detail must be called with either an object pk or a slug.  (Прочитано 1542 раз)

AdminUser

  • Team Lead
  • Юный джедай
  • *****
  • Сообщений: 65
  • Репутация +8/-0
    • Просмотр профиля
Привет

Написал url с аргументом:

url(r'^users/([0-9]+)/', ProfileView.Detail.as_view()),
для доступа к элементу Profile через DetailView:

class Detail(DetailView):
    model = Profile
    template_name = "home.html"
    context_object_name = 'profile'                                # по умолчанию object или objects

    def get_context_data(self, *args, **kwargs):
        context = super(Detail, self).get_context_data(*args, **kwargs)
        context['header'] = "Профиль"
        return context

Получаю ошибку:

Цитата:
Generic detail view Detail must be called with either an object pk or a slug.

Как исправить?

DigitalMag

  • Юный джедай
  • **
  • Сообщений: 89
  • Репутация +6/-0
    • Просмотр профиля
Re: Generic detail view Detail must be called with either an object pk or a slug.
« Ответ #1 : Марта 10, 2019, 02:29:02 pm »
Исправьте:
url(r'^users/(?P<pk>[0-9]+)/', ProfileView.Detail.as_view()),