Browse Source

feat: Video Site App - 4. Display uploaded video

master
Bobson Lin 2 years ago
parent
commit
f276102ad1
6 changed files with 34 additions and 7 deletions
  1. +19
    -0
      .vscode/launch.json
  2. +3
    -3
      video_site/core/templates/core/video.html
  3. +1
    -1
      video_site/core/urls.py
  4. +5
    -2
      video_site/core/views.py
  5. +3
    -0
      video_site/video_site/settings.py
  6. +3
    -1
      video_site/video_site/urls.py

+ 19
- 0
.vscode/launch.json View File

@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python:Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/video_site/manage.py",
"args": [
"runserver",
// "--noreload"
],
"django": true
}
]
}

+ 3
- 3
video_site/core/templates/core/video.html View File

@ -7,7 +7,7 @@
<section class="section">
<div class="container">
<video controls>
<source src="earth_video.mp4" type="video/mp4" />
<source src="{{ the_video.video_file.url }}" type="video/mp4" />
</video>
</div>
</section>
@ -19,14 +19,14 @@
<!-- Left side -->
<div class="level-left">
<div class="level-item">
<h1 class="title">Video Title</h1>
<h1 class="title">{{ the_video.title }}</h1>
</div>
</div>
<!-- Right side -->
<div class="level-right">
<p class="level-item">
<strong>11 hours ago</strong>
<strong>{{ the_video.date }}</strong>
</p>
</div>
</nav>


+ 1
- 1
video_site/core/urls.py View File

@ -3,5 +3,5 @@ from . import views
urlpatterns = [
path('', views.index, name='index'),
path('video/', views.video, name='video')
path('video/<int:video_id>/', views.video, name='video')
]

+ 5
- 2
video_site/core/views.py View File

@ -1,9 +1,12 @@
from django.shortcuts import render
from .models import Video
def index(request):
return render(request, 'core/index.html')
def video(request):
return render(request, 'core/video.html')
def video(request, video_id):
the_video = Video.objects.get(pk=video_id)
context = {'the_video': the_video}
return render(request, 'core/video.html', context)

+ 3
- 0
video_site/video_site/settings.py View File

@ -119,3 +119,6 @@ USE_TZ = True
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
MEDIA_ROOT = BASE_DIR
MEDIA_URL = '/media/'

+ 3
- 1
video_site/video_site/urls.py View File

@ -15,8 +15,10 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('core.urls'))
]
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Loading…
Cancel
Save