@websamson

Как исправить ошибку CreateView: must be called with either an object pk or a slug in the URLconf?

Изучаю книгу William S. Vincent "Django для начинающих". Не работает пример из книги. Выдает: ""Generic detail view BlogCreateView must be called with either an object pk or a slug in the URLconf". В чем может быть ошибка?

В urls:
urlpatterns = [
...
    path('post/new/', views.BlogCreateView.as_view(), name='post_new'),
]


В views:
class BlogCreateView(DetailView):
    model = Post
    template_name = 'post_new.html'
    fields = '__all__'


В post_new.html:
{% extends 'base.html' %}

{% block content %}
    <h1>New post</h1>
    <form action = "" method = "post">{% csrf_token %}
        {{ form.as_p }}
        <input type="submit" value="Save" />
    </form>
{% endblock %}
  • Вопрос задан
  • 59 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы