Skip to content

Commit 055d9d7

Browse files
Django media support
1 parent f90a134 commit 055d9d7

File tree

23 files changed

+347
-83
lines changed

23 files changed

+347
-83
lines changed

.pylintrc

6 Bytes
Binary file not shown.

Django/#Guide2.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
3+
1. open settings.py and paste to end of it
4+
5+
STATICFILES_DIRS = [
6+
os.path.join(BASE_DIR, 'static'),
7+
]
8+
9+
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
10+
11+
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
12+
MEDIA_URL = '/media/'
13+
14+
2. in urls
15+
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
16+
17+
18+
https://overiq.com/django/1.10/handling-media-files-in-django/
19+
https://stackoverflow.com/questions/32668959/play-audio-audio-file-in-django-template
20+
21+
3. create media folder in main project
121 Bytes
Binary file not shown.
160 Bytes
Binary file not shown.

Django/MyDjangoApp/MyDjangoApp/settings.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,14 @@
119119
# https://docs.djangoproject.com/en/2.1/howto/static-files/
120120

121121
STATIC_URL = '/static/'
122+
123+
124+
125+
STATICFILES_DIRS = [
126+
os.path.join(BASE_DIR, 'static'),
127+
]
128+
129+
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
130+
131+
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
132+
MEDIA_URL = '/media/'

Django/MyDjangoApp/MyDjangoApp/urls.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@
1616
from django.contrib import admin
1717
from django.urls import path,include
1818

19+
from django.conf import settings
20+
from django.conf.urls.static import static
21+
22+
23+
1924
urlpatterns = [
2025
path('admin/', admin.site.urls),
2126
path('music/', include('music.urls')),
22-
2327
]
28+
29+
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
30+

Django/MyDjangoApp/Rough book.txt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{% for album in all_albums %}
2+
<div class="CardAlbum">
3+
<a id="album_title" href = "{% url 'music:detail' album.id %}">
4+
<img id="album_logo" src="{{ album.album_logo }}" alt="Avatar" >
5+
</a>
6+
<div class="AlbumContainer">
7+
<h4><b>{{ album.album_title }}</b></h4>
8+
<p>{{album.artist}}</p>
9+
</div>
10+
</div>
11+
<br>
12+
13+
{% endfor %}
14+
15+
16+
17+
18+
{% extends 'music/base.html' %}
19+
{% block title %} detail {% endblock%}
20+
{% block body%}
21+
22+
<img src = " {{ album.album_logo }} ">
23+
<h1> {{ album.album_title }} </h1>
24+
<h3>{{ album.artist }}</h3>
25+
26+
<hr> <hr>
27+
28+
{% if error_message %}
29+
<p><Strong> {{ error_message }}</Strong></p>
30+
31+
32+
33+
{% endif %}
34+
35+
{% for song in album.song_set.all %}
36+
37+
<audio controls>
38+
<source src="" type="audio/ogg">
39+
<source src="{{link.url}}/{{song.file_type}}" type="audio/mpeg">
40+
<button> "{{song.file_type}}"</button>
41+
Your browser does not support the audio element.
42+
</audio>
43+
44+
{{song.song_title}}
45+
46+
{% endfor %}
47+
48+
49+
{% endblock%}
50+
51+
52+
<!-- <input type="radio" id="song{{ forloop.counter }}" name="song" value="{{ song.id }}">
53+
<label for="song{{ forloop.counter }}">
54+
{{ song.song_title }}
55+
{% if song.is_favourite %}
56+
<img src ="http://i.imgur.com/b9b13Rd.png"/>
57+
{% endif %}
58+
</label> <br> -->
59+
60+
61+
62+
<audio controls>
63+
<source src="{{link.url}}/media/audio/NishantGhanate/Song.mp3" type="audio/mpeg">
64+
Your browser does not support the audio element ().
65+
</audio>
66+
67+
<hr>
68+
{{link.url}}
69+
<hr>

Django/MyDjangoApp/db.sqlite3

0 Bytes
Binary file not shown.
1.39 MB
Binary file not shown.
1.39 MB
Binary file not shown.

0 commit comments

Comments
 (0)