0

This is my settings.py:

DEBUG = False

ALLOWED_HOSTS =  ['localhost', '127.0.0.1']

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

main urls.py:

handler404 = 'home.views.custom_page_not_found_view'

my views for 404 page:

def custom_page_not_found_view(request, exception):
    return render(request, "404.html", {}, status=404)

i tryed this solution:(Correct way of implementing custom 404 page in Django 3 in production) but it doesn't work and kept getting server 500 error responses

how do i fix this?

MMEEUR
  • 57
  • 6
  • Just create a `404.html` at your `templates` folder and let [Django default error view](https://docs.djangoproject.com/en/4.1/ref/views/#error-views) handle everything else. – Niko Jan 10 '23 at 15:47
  • At first, I did the same thing, but it gives error 500 – MMEEUR Jan 10 '23 at 16:28
  • I just tested with [Django 3.0](https://pypi.org/project/Django/3.0/) and it works normally. [3.0 documentation on error](https://docs.djangoproject.com/en/3.0/ref/views/#error-views). Just make sure you have `404.html` placed at the root of template folder. – Niko Jan 10 '23 at 17:31
  • I don't understand why it gives such an error, no matter what I did, it didn't work When I add the 500.html file, it gives a new error A server error occurred. Please contact the administrator. Could it be because of using the if, extends or block tag? – MMEEUR Jan 10 '23 at 19:06

1 Answers1

0

This error was because I had used the extends tag inside the 404.html file

MMEEUR
  • 57
  • 6