I'm new to using Django and I'm trying to write test for my pages app but I keep on getting the same error when testing for the homepage url name

urls.py

from django.urls import path
from pages.views import HomePageView

app_name = 'pages'

urlpatterns = [
     path('', HomePageView.as_view(), name='home'),
]

test.py

from django.test import SimpleTestCase
from django.urls import reverse

class HomePageTest(SimpleTestCase):

    def test_homepage_url(self):
        response = self.client.get('/')
        self.assertEqual(response.status_code, 200)

    def test_homepage_name(self):
        url = reverse('home')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

    def test_homepage_template(self):
        response = self.client.get('/')
        self.assertTemplateUsed(response, 'home.html')

views.py

from django.shortcuts import render
from django.views.generic import TemplateView

class HomePageView(TemplateView):
    template_name = 'pages/home.html'

pages/home.html

{% extends 'base.html' %}


{% block title %}Home{% endblock title %}


{% block content %}
  Welcome
{% endblock content %}
1

There are 1 answers

0
michjnich On BEST ANSWER

You don't specify, but I assume it's test_homepage_name that is giving the error?

Try including the app name:

url = reverse('pages:home')