반응형
  • 이미 가지고 있는 테이블을 기반으로 장고 마이그레이션이 필요할 경우 아래의 명령어로 테이블 스키마 기준 models 데이터를 생성 할 수 있다.
python manage.py inspectdb > models.py

 

반응형

반응형

다운로드 받을 파일 타입(Mimetype) 구분 방법

import mimetypes

mimetypes.guess_type('test.png')  # return ('image/png', None)

 

 

    import mimetypes
    import urllib
    
    
    file_name = urllib.parse.quote(file_info.file_name.encode('utf-8'))

    if os.path.exists(file_path):
        with open(file_path, 'rb') as fh:
            response = HttpResponse(fh.read(), content_type=mimetypes.guess_type(file_path)[0])
            response['Content-Disposition'] = 'attachment;filename*=UTF-8\'\'%s' % file_name
            return response

 

반응형

+ Recent posts