I'm using django 3, when I upload a video from the admin panel, it doesn't appear on the page. When I go to the video url, I get a 404 error, but my old uploads are visible, and the newly uploaded files are not visible. My English is not very good, I translated it with google translate and I'm sorry if there are any mistakes
from curses import meta
from django.db import models
from autoslug import AutoSlugField
from django.forms import SlugField
import os
from uuid import uuid4
def path_and_rename(path):
def wrapper(instance, filename):
ext = filename.split('.')[-1]
# get filename
if instance.pk:
filename = '{}.{}'.format(instance.pk, ext)
else:
# set filename as random string
filename = '{}.{}'.format(uuid4().hex, ext)
# return the whole path to the file
return os.path.join(path, filename)
class VideoModel(models.Model):
name= models.CharField(max_length=250, default='Video Adı', verbose_name='Baslik')
video= models.FileField(upload_to=path_and_rename('video'), verbose_name='Video')
slug = AutoSlugField(populate_from="name", unique=True)
class Meta:
verbose_name='Videolar'
verbose_name_plural = 'Video'
db_table = 'videolar'
def __str__(self) -> str:
return self.name
base.html ( There are no views because I use it on the homepage)
{% for video in videolar %}
<div class="col-sm-6 col-md-4 col-lg-3 item"><video width="300" height="300" controls="controls">
<source src="{{video.video.url}}" type="video/mp4" /><br>
Tarayıcınız video etiketini desteklemiyor.
</video>
<p class="align-items-center">{{video.name}}</p>
</div>
{% endfor %}