Skip to end of metadata
Go to start of metadata
You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
Version 1
Next »
1. 이미지 업로드(동영상, 파일 업로드도 동일)
1) urls.py에 업로드 경로를 등록합니다.
# urls.py
urlpatterns = [
...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
2) models.py에 모델을 생성합니다.
# models.py
from django.db import models
import uuid
import os
def get_file_path(instance, filename):
ext = filename.split('.')[-1]
filename = "%s.%s" % (uuid.uuid4(), ext)
return os.path.join('uploads/', filename)
class UploadFile(models.Model):
file = models.FileField(upload_to=get_file_path)