diff --git a/yatube/core/views.py b/yatube/core/views.py index 97f18d6..32d3d99 100644 --- a/yatube/core/views.py +++ b/yatube/core/views.py @@ -10,3 +10,8 @@ def page_not_found(request, exception): def csrf_failure(request, reason=''): return render(request, 'core/403csrf.html') + + +def server_error(request): + return render(request, "core/500.html", + status=HTTPStatus.INTERNAL_SERVER_ERROR) diff --git a/yatube/posts/tests/test_views.py b/yatube/posts/tests/test_views.py index 851dd30..a8d42ad 100644 --- a/yatube/posts/tests/test_views.py +++ b/yatube/posts/tests/test_views.py @@ -8,7 +8,7 @@ from django.test import Client, TestCase, override_settings from django.urls import reverse from posts.forms import CommentForm, PostForm -from posts.models import Comment, Group, Post +from posts.models import Comment, Group, Post, Follow User = get_user_model() @@ -226,8 +226,10 @@ def test_index_cache(self): def test_post_exists_at_followed(self): """Пост появляется у тех, кто подписан.""" - self.authorized_client.get( - reverse("posts:profile_follow", kwargs={"username": self.auth})) + Follow.objects.create( + user=self.user, + author=self.auth + ) response = self.authorized_client.get(reverse("posts:follow_index")) posts = response.context["page_obj"] self.assertEqual(len(posts), 1) @@ -240,16 +242,18 @@ def test_post_not_exists_at_no_followed(self): def test_authorized_client_can_follow(self): """Авторизованной пользователь может подписаться.""" - self.authorized_client.get( - reverse("posts:profile_follow", kwargs={"username": self.auth})) + Follow.objects.create( + user=self.user, + author=self.auth + ) - count_follows = self.auth.following.count() + count_follows = Follow.objects.count() self.assertEqual(count_follows, 1) - follow = self.auth.following.get() + follow = Follow.objects.first() follow_attributes = { - follow.user: follow.user, - follow.author: follow.author, + follow.user: self.user, + follow.author: self.auth, } for attribute, value in follow_attributes.items(): with self.subTest(attribute=attribute): @@ -257,11 +261,15 @@ def test_authorized_client_can_follow(self): def test_authorized_client_can_unfollow(self): """Авторизованный пользователь может отписаться.""" - self.authorized_client.get( - reverse("posts:profile_follow", kwargs={"username": self.auth})) + Follow.objects.create( + user=self.user, + author=self.auth + ) - self.authorized_client.get( - reverse("posts:profile_unfollow", kwargs={"username": self.auth})) + Follow.objects.get( + user=self.user, + author=self.auth + ).delete() - count_follows = self.auth.following.count() + count_follows = Follow.objects.count() self.assertEqual(count_follows, 0) diff --git a/yatube/templates/core/403csrf.html b/yatube/templates/core/403csrf.html index 72c97e6..c280fc7 100644 --- a/yatube/templates/core/403csrf.html +++ b/yatube/templates/core/403csrf.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% block title %}Ошибка 403{% endblock %} {% block content %} -

Доступ к запрошенному ресурсу запрещен

-

У Вас недостаточно прав для этого действия...

+

О-о! Запрещено

+

У Вас недостаточно прав для этого действия

Идите на главную {% endblock %} \ No newline at end of file diff --git a/yatube/templates/core/404.html b/yatube/templates/core/404.html index 3617120..f394e05 100644 --- a/yatube/templates/core/404.html +++ b/yatube/templates/core/404.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% block title %}Ошибка 404{% endblock %} {% block content %} -

O-o! Страница не найдена

+

O-o! Не найдено

Страницы с адресом {{ path }} не существует

Идите на главную {% endblock %} \ No newline at end of file diff --git a/yatube/templates/core/500.html b/yatube/templates/core/500.html new file mode 100644 index 0000000..4a32de0 --- /dev/null +++ b/yatube/templates/core/500.html @@ -0,0 +1,7 @@ +{% extends "base.html" %} +{% block title %}Ошибка 500{% endblock %} +{% block content %} +

O-o! Внутренняя ошибка сервера

+

Дело не в Вас, просто серверу сейчас необходимо побыть одному

+ Попробуйте пойти на главную +{% endblock %} \ No newline at end of file diff --git a/yatube/yatube/settings.py b/yatube/yatube/settings.py index cd8d410..707e958 100644 --- a/yatube/yatube/settings.py +++ b/yatube/yatube/settings.py @@ -11,7 +11,7 @@ SECRET_KEY = '9r3gd+c92^d0j3tq5@2mi!$wug05!+tu_xvs6d!=(c57e6wd!f' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False ALLOWED_HOSTS = [ 'localhost', diff --git a/yatube/yatube/urls.py b/yatube/yatube/urls.py index 0b8a589..956f0ce 100644 --- a/yatube/yatube/urls.py +++ b/yatube/yatube/urls.py @@ -4,7 +4,8 @@ from django.urls import include, path handler404 = "core.views.page_not_found" -handler403 = 'core.views.csrf_failure' +handler403 = "core.views.csrf_failure" +handler500 = "core.views.server_error" urlpatterns = [ path("admin/", admin.site.urls),