For some reason the play button is greyed out on my Django website. I used this same exact HTML code in a blank HTML document and it worked as it should, so I don't think there's a problem finding the file, or a syntax error. While running the server locally I am not seeing any errors in the command line either.
How it looks on blank HTML file
Code:
<audio src="C:\Users\zach2\music\download.mp3" controls>
</audio>
Is there something that I need to change in one of the Django files to enable audio to work properly? I am very new to Django and Web development so please forgive my ignorance. If you want to see another file please let me know and I will update the post ASAP. Thank you.
CodePudding user response:
You can put the file inside your server root (within a media or assets directory) instead of trying to load it directly from that path.
Local files are generally not accessible to a browser for security reasons. Else any website would be able to access your sensitive files just by guessing and putting in the most common paths.
CodePudding user response:
One thing is you cannot access local on hosted website may it be local or remote files, unless you are using blank HTML page just like you did. This is because of a security concerns.
If you do want to server your media files such as audio, images, videos, etc. normally you can put it inside media folder inside your django app directory if you are handling with user uplodaded files or any non-static files.
To handle staticfiles and mediafiles in django you can refer to this link https://docs.djangoproject.com/en/3.2/howto/static-files/