Django Rest Framework Uploaded File Url

Viewed 2227

Django rest framework automatically generates urls for uploaded files. However, the url it automatically generates doesn't actually point to where the file is stored. For example, I upload a file to my api named example.txt and this is what the object in my database looks like after the upload:

{
    name: "John Doe",
    bio: "localhost:8000/api/users/static/example.txt"
}

My static directory is located in the root directory so the file actually lives and can be accessed at localhost:8000/static/example.txt. The automatically generated url returns a 404. How can I overwrite the automatically generated url to be the correct one?

Here's what my model looks like:

class User(models.Model):
   name = models.CharField(primary_key=True, max_length=30)
   bio = models.FileField(null=True, blank=True, upload_to='static')

Here's what the serializer looks like:

class UserSerializer(serializers.ModelSerializer):
   class Meta:
     model = User
     fields = ("name", "bio")
1 Answers
Related