‘FieldFile’ object has no attribute ‘replace’

Python 3.7.2, Django 2.2

This error message doesn’t really explain anything, and the trace that shows in the browser or console window doesn’t help either.

The problem is when using a FileField object as a string in your template. This wasn’t a problem with earlier versions of Django.

<meta name="pdf_url" content="{% static mymodel.pdf %}">

Simply append .url and you’ll be fine.

<meta name="pdf_url" content="{% static mymodel.pdf.url %}">

You May Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *