I couldn't play the audios that were uploaded to admin (the urls have quotation marks)

44 Views Asked by At

I created a new class in my model.py file:

class Audio(models.Model):
    .....
    audio_object = models.FileField(default='')

And I uploaded my audios to my admin page. However, the audios don't play and I right-clicked to a new browser, it shows "Page Not Found" saying "The current path, appname/“/media/nameoftheaudio.mp3”, didn't match any of the URLconf defined in projectname.urls.

I reviewed the answers from Django MEDIA_URL and MEDIA_ROOT but it didn't solve my problems. In my urls.py, I already have:

from django.conf import settings
from django.conf.urls.static import static

urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

And in my setting.py, I have:

STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'assets'),
)

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

Another piece of information is the audios I uploaded to another class work fine! And that is the first class model I created in this project. I can't detect what do I lack for this Audio class. I am using Django 3.0.4 Thank you!!

Update: I think I found the issue: when I open the link for my audio, there are always quotation marks attached for "media/audio.mp3". My screenshot

How can I remove the quotation marks; I am pretty sure several days ago the media files work fine but ever since I added a new class it became like this. Many thanks for your help!!!

0

There are 0 best solutions below