Bootuz
Bootuz

Reputation: 557

Audio doesn't play. Django, DEBUG = False

Have a problem with audio playing again. Now in deploy with DEBUG = False. This is my settings:

    STATIC_ROOT = '/home/bootuz/final/myapp/static/'

    STATIC_URL = '/static/'

    MEDIA_ROOT = '/home/bootuz/final/audio/'

    MEDIA_URL = '/media/'

This code I added to urls.py

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

Template:

<audio id="player" preload="auto">
                <source src="{{ showword.audio.url }}" type="audio/mpeg">
                </audio>
                <button id="player_button" onclick="document.getElementById('player').play()"><img src="{% static 'images/audio.png' %}" alt="Play">
                </button>

And in the console I see this error:

enter image description here Could you tell me, guys, what is wrong?

Upvotes: 2

Views: 368

Answers (1)

tutuDajuju
tutuDajuju

Reputation: 10870

As others have stated in the comments, serving static files using Django is not advisable. In fact, the documentation has this to say about the static() function:

This is not suitable for production use! For some common deployment strategies, see Deploying static files.

And further notes that:

This helper function works only in debug mode and only if the given prefix is local (e.g. /static/) and not a URL (e.g. http://static.example.com/).

Also this helper function only serves the actual STATIC_ROOT folder; it doesn’t perform static files discovery like django.contrib.staticfiles.

Please refer to the linked documentation for common scenarios of serving static files in production.

Upvotes: 1

Related Questions