Issue
When I test the simple app according to tutorial 'AssertionError: 404 != 200' is occured. Can anybody fix this problem? (Project name: simple_project, app name inside the project: pages)
My app-level urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('', views.HomePageView.as_view(), name='home'),
path('about/', views.AboutPageView.as_view(), name='about'),
]
My app-level views.py:
from django.views.generic import TemplateView
class HomePageView(TemplateView):
template_name = 'home.html'
class AboutPageView(TemplateView):
template_name = 'about.html'
My project-level urls.py:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('pages.urls')),
]
My tests.py:
from django.test import SimpleTestCase
class SimpleTests(SimpleTestCase):
def test_home_page_status_code(self):
response = self.client.get('/')
self.assertEquals(response.status_code, 200)
def test_abaout_page_status_code(self):
response = self.client.get('about')
self.assertEquals(response.status_code, 200)
When I test, this error is occured:
FAIL: test_abaout_page_status_code (pages.tests.SimpleTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\User\Dj\simple\pages\tests.py", line 10, in test_abaout_page_status_code
self.assertEquals(response.status_code, 200)
AssertionError: 404 != 200
Solution
def test_abaout_page_status_code(self):
response = self.client.get('/about/')
self.assertEquals(response.status_code, 200)
try this
Answered By - Exprator
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.