Hi everybody,
I have a Class based view:
class PromocionListView(ListView):
model = Promocion
and this url path:
urlpatterns = [
path('promocion/list', PromocionListView.as_view(), name='promocion_list')]
so I made the following test:
class PromocionTests(TestCase):
@classmethod
def setUpTestData(cls):
cls.promocion = Promocion.objects.create(fecha_de_inicio = date(2022,7,6),duracion = 90)
def test_url_exists_at_correct_location(self):
response = self.client.get('promocion/list')
self.assertEqual(response.status_code, 200)
but it is showing the error: AssertionError: 404 != 200. Does anything knows why this is happening? I googled it a lot but I couldn’t find an answer
Is that url in your root urls.py file? If not, what urls.py file is it in and what url leads you to that entry?
Have you tried accessing that url as an absolute url? (/promocion/list
)
Additionally if you install django-extensions there’s a really neat command called show_urls
. I use that frequently when I’m having Django URL routing issues.
1 Like
Hello, thanks for answer. No, the url lives in he urls.py file of the app.
urlpatterns = [ ... path('dashboard/', include('dashboard.urls')) ]
as you can see the app’s name is dashboard, so it is included in the root urls.py file. The dahsboard app has its own urls.py file whit the path that I write in the question in it. Sorry for my bad english. I hope you can understand me
I also tried to to access the url in the way you´re pointing. But it doesn´t still work
If the full path of that url is /dashboard/promocion/list, then that is the url you need to use.
OK, I’ll try it and and wirte you again. Thanks!
Oh that was all! If worked perfectly! Than you very much for your invaluable help.