python - imagefield never upload in my template -


i user django, create dynamic blog site dadabase , templates htmal/css upload new post fine.

now want upload on post images create new field in database

image1 = model.imagefield(upload_to="/images/imagethumb/") 

i can login admin , create new post photo photo never see template.

from research in internet, think problem in settings.py or upload_to media_root , media_url , apache folder.my /images/imagethumb/ must in media folder?

add following in settings.py file

media_root = os.path.join(base_dir, 'media') media_url = '/media/' 

create 'media' in project @ same level 'manage.py'. add following line @ end of project urls.py file.

urlpatterns += static(settings.media_url, document_root=settings.media_root) 

now image stored in /media directory. can access following path

/media/image.png

it if share directory structure well.

mysite       your_app       mysite             urls.py       media       manage.py 

you have add above mentioned line in urls.py shown in above directory structure.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -