[Fixed]-Django display filefield in Template

1👍

I hate my life

i missed the $ in one of my urls.py

what i had

url(r'^', views.index, name='index'),

what i changed to

url(r'^$', views.index, name='index'),

It took me more than 24 hours to figure it out but i still dont know why only the files that i wanted to get were affected

0👍

In the for loop

<audio controls>
  <source src="{{audios.Audio_File.url}}" type="audio/{{audios.Audio_File.type}}">

  
  Your browser does not support the audio tag.
</audio>

At least we will know if the browser is supporting the audio and then we will debug it from there.

0👍

I believe that you should first configure your static and media in settings

BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
ROOT_PATH = os.path.abspath(os.path.dirname(__file__))
PROJECT_DIR = os.path.dirname(os.path.dirname(__file__))


import os.path
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(ROOT_PATH, 'static/')

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

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader'
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',

)

then just put some file in static and try to access it through browser, then check your Audio_File.url so it’s generating properly

Leave a comment