我想在Django中播放音頻,但它無法找到音頻文件。我已經設置了MEDIA_URL和MEDIA_ROOT,但它仍然不起作用。請幫幫我。 下面是代碼片段圖像和聲音(媒體)不顯示在Django
settings.py
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
urls.py
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^$',home),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT
home.html做爲
{% extends "layout/base.html" %}
{% block content %}
<h1> Sound Assessment Toolset </h1>
<audio src="{{MEDIA_URL}}master_sound/piano.mp3"></audio>
<img src="{{ MEDIA_URL }}images/batman.jpg"/>
{% endblock %}
日誌文件:
Django version 1.8.7, using settings 'Sound_Assessment.settings'
Starting development server at http://127.0.0.1:8800/
Quit the server with CONTROL-C.
[17/Jun/2016 15:18:43] "GET/HTTP/1.1" 200 746
[17/Jun/2016 15:18:43] "GET /images/batman.jpg HTTP/1.1" 404 2321
[17/Jun/2016 15:18:43] "GET /master_sound/piano.mp3 HTTP/1.1" 404 2336
[17/Jun/2016 15:18:43] "GET /images/batman.jpg HTTP/1.1" 404 2321
謝謝。這工作。 –