Page tree
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

« Previous Version 4 Next »

1. 이미지 업로드(동영상, 파일 업로드도 동일)

1) urls.py에 업로드 경로를 등록합니다.

# urls.py
urlpatterns = [
	...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

2) models.py에 모델을 생성합니다.

# models.py
import uuid
from django.db import models

# 저장할 파일 이름을 반환합니다.
def get_file_name(instance, filename):
    ext = filename.split('.')[-1]
    return "%s.%s" % (uuid.uuid4(), ext)

class UploadFile(models.Model):
    file = models.FileField(upload_to=get_file_name)
  • No labels