Flatpages not working on production but working on localhost.

Hello everyone,

I am stuck on this for a couple of days now.

I create faltpages through the django-oscar dashboard on my website, i set the urls to something like /langusge_code/cookies-policy/ or just /cookies-policy/.
When I then go visit that url path on my localhost i see each corresponding page with the content i put on it.

I pushed this to production and when I visit the flatpages I have created on the production dashboard, I get 404 for the ones with the format /url/ and timeout for the ones with the format /language_code/url/. I have set the SITE_ID = 1 in settings, added the flatpages middleware in the end of the middleware section and the sites and flatpages in installed apps, I have also set the deployment website in the sites section in django-admin on production and made sure it’s ID is 1. Lastly i connected each flatpage to it through django-admin again.

Any help is welcome!
Have a good one.

What’s the configured domain name for the Site with ID 1?
Does that match your production domain name, where you’re trying to access the page?

You need to set the domain value to match your production environment.
This is covered on the Enabling the sites framework

django.contrib.sites registers a post_migrate signal handler which creates a default site named example.com with the domain example.com . This site will also be created after Django creates the test database. To set the correct name and domain for your project, you can use a data migration.

Hello @leandrodesouzadev and thanks for the quick reply.

The deployment site url matches the url of the site with SITE_ID=1.

I have ran the migrate command on the server machine and in the operations message it displays ‘flatpages’.

I have checked the SITE_ID of the site url i have set on the deployment server through the database tables as well and they match.

When hosting locally, i set the site (in django-admin → sites) to localhostIP:8000 and connect each flatpage to it (in django-admin → flatpages). I can visit my flatpages fine.
I do the same thing on the deployment server and set the url to the server’s domain name but then the requests for the flatpages seem to take too long and i get a timeout.

I solved it.

In templates/flatpages/default.html I had some blocks for meta tags containing static image paths that were not present on the deployment server.

Each time the server tried loading the default.html template it was looking for these static image files forever and timing out because it could not find them.

Steps:
1.Removed the static files references from default.html

2.Ran: “./manage.py collectstatic --clear --link --noinput -v 1” on the server.

Well done.

But it sounds odd that your server wouldn’t immediately respond to requests for missing images with a 404 Not Found response. Instead it sounds like it’s not returning a response and timing out?

There may be something wrong with whatever’s serving your static files. It could become a problem if, for some reason, you got several requests for missing static files - the server would sit there waiting for all the requests to time out, and may not be able to respond to other requests at all.