Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7974835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:29:37+00:00 2026-06-04T08:29:37+00:00

I am trying to automate 404 pages testing using Django 1.4’s testing framework. If

  • 0

I am trying to automate 404 pages testing using Django 1.4’s testing framework.

If I print 127.0.0.1:8000/something/really/weird/ in browser address bar with development server running, I see a 404 page, with correct “404 NOT FOUND” status (as firebug shows).

But if I try to use this code for testing:

from django.test import TestCase
class Sample404TestCase(TestCase):
    def test_wrong_uri_returns_404(self):
        response = self.client.get('something/really/weird/')
        self.assertEqual(response.status_code, 404)

the test fails with this output:

$./manage.py test main
Creating test database for alias 'default'...
.F
======================================================================
FAIL: test_wrong_uri_returns_404 (main.tests.Sample404TestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ".../main/tests.py", line 12, in test_wrong_uri_returns_404
    self.assertEqual(response.status_code, 404)
*AssertionError: 200 != 404*

----------------------------------------------------------------------
Ran 2 tests in 0.031s

FAILED (failures=1)
Destroying test database for alias 'default'...

I’m seriously surprised with getting 200 code here. Anyone have any idea why on earth this is happening?

updated:

here lies urls.py: http://pastebin.com/DikAVa8T
and actual failing test is:

def test_wrong_uri_returns_404(self):
    response = self.client.get('/something/really/weird/')
    self.assertEqual(response.status_code, 404)

everything is happening in project https://github.com/gbezyuk/django-app-skeleton

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:29:38+00:00Added an answer on June 4, 2026 at 8:29 am

    The problem is that your ViewFor404 class returns a 200 status code. Look at Django’s TemplateView definition:

    class TemplateView(TemplateResponseMixin, View):
        """
        A view that renders a template.
        """
        def get_context_data(self, **kwargs):
            return {
                'params': kwargs
            }
    
        def get(self, request, *args, **kwargs):
            context = self.get_context_data(**kwargs)
            return self.render_to_response(context)
    

    so all your class does is a render_to_response, which generates a ‘200’ response.

    If you need to override the 404 handler, you should do something more like this in the view:

    return HttpResponseNotFound('<h1>Page not found</h1>')
    

    (I don’t know the equivalent in class-based views)

    Or better yet, can you avoid customizing the View? To customize the 404 display, you can just create a 404.html template (in your site’s templates/ directory), and it will be picked up by Django’s error viewer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to automate functional testing of a server using a realistic frequency
I'm currently trying to automate a test case using the White UI-Automation framework .
I am trying to automate data extraction from a website and I really don't
I'm trying to automate the build of a project in Delphi 2009. I'm using
I am trying to automate the creation of something like this: <input type='text' name='asdf[]'
I am trying to automate a web application having javascript. I am using WWW::Scripter
I am trying to automate the testing of RESTful services, and researching tools that
I'm trying to automate menu picks using Microsoft UI Automation. The application that I'm
I am trying to automate testing of WP7 apps. In my app, one functionality
I'm trying to automate a gdb session using the --command flag. I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.