리셋 되지 말자

django local image database save 본문

Django

django local image database save

kyeongjun-dev 2021. 10. 12. 19:07

https://stackoverflow.com/questions/1308386/programmatically-saving-image-to-django-imagefield

 

Programmatically saving image to Django ImageField

Ok, I've tried about near everything and I cannot get this to work. I have a Django model with an ImageField on it I have code that downloads an image via HTTP (tested and works) The image is saved

stackoverflow.com

 

Super easy if model hasn't been created yet:

First, copy your image file to the upload path (assumed = 'path/' in following snippet).

Second, use something like:

class Layout(models.Model): image = models.ImageField('img', upload_to='path/') layout = Layout() layout.image = "path/image.png" layout.save()

tested and working in django 1.4, it might work also for an existing model.

Share

Improve this answer

Follow

answered Oct 16 '12 at 15:11

Rabih Kodeih

8,80811 gold badges44 silver badges

 

'Django' 카테고리의 다른 글

CSRF 토큰 오류  (0) 2021.12.21
celery shared_task 수집하기  (0) 2021.10.12
filter, get 차이  (0) 2021.10.12
message 사용하기  (0) 2021.05.06
migrate 테이블 생성 안할때  (0) 2021.05.02
Comments