Question

NotImplementedError at /repost/577/ This backend doesn't support absolute paths.

Hi, there

I have an error when in my django DO app.

When I am reposting posts with screenshots I get this error in production:

NotImplementedError at /repost/577/ This backend doesn’t support absolute paths. Request Method: POST Request URL: https://www.sportsfamly.com/repost/577/

However the error is not there in development in local server.

All other post can be reposted - those that have text, videos, and JPEG photos, its only those that have screenshots that produce the error.

Let me also add that after I refresh the browser I discover that the post was reposted.

How can I resolved this?

I was thinking that if there is a way to escape the error it might resolve the issue as I mentioned that the post with the screenshot producing the error is reposted


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
February 8, 2024

Hey Chris,

It sounds like you’re encountering a somewhat strange issue with your Django application when running on the DigitalOcean App Platform, especially concerning posts with screenshots. The error message you’re receiving, NotImplementedError at /repost/577/ This backend doesn’t support absolute paths, gives us a good starting point to troubleshoot.

This error typically occurs when your application is trying to access a file or resource using an absolute file path, but the storage backend configured in your Django settings does not support this operation. In a production environment, especially on platforms like the DigitalOcean App Platform, your static and media files are often served differently than in a local development environment, which might be why you’re only encountering this issue in production.

Here are some things that you should start checking:

  1. Check Your Storage Backend: First, verify what file storage backend you’re using in your production environment. If you’re using Django’s default file storage system, it works well with local filesystem paths. However, in production, especially with Kubernetes based systems like the App Platform, where the local storage is ephemeral, you should be using a different storage like DigitalOcean Spaces which require different configurations. Otherwise if you use the local ephemeral storage, every time you do a redeployment, your local files will be lost.

  2. Review File Upload Handling: For files like screenshots that are uploaded by users, ensure your application handles these uploads correctly with your configured storage backend. If you’re using the DigitalOCean spaces, you should use the appropriate Django storage backend library, such as django-storages, and configure it to work with your service:

https://www.digitalocean.com/community/tutorials/how-to-set-up-object-storage-with-django

  1. Use Relative Paths: Modify your application to use relative paths or URLs provided by your storage backend instead of absolute filesystem paths. This is crucial for compatibility with storage backends that don’t operate on the local filesystem.

Besides that, here are some debugging tips:

  • As per the article that I’ve shared above, review your Django settings for MEDIA_URL and STATIC_URL to ensure they’re correctly set for your production environment.
  • Double-check the DEFAULT_FILE_STORAGE setting in your Django settings.
  • Look into the stack trace provided by the error to pinpoint exactly where in your code the issue is occurring. It might give you more insight into whether it’s the saving or retrieving of the file that’s causing the problem.

Since you mentioned that the post eventually gets reposted after refreshing, it indicates the operation might be succeeding, but the path resolution for the redirect or response is where the issue lies. This further emphasizes the need to ensure your application’s file path handling aligns with the capabilities of your storage backend.

I hope this helps you get to the bottom of the issue, let me know how it goes!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel