DEV Community

SOLVED:Uploading images from Django-Admin

Vicente G. Reyes on May 09, 2019

I'm almost done fixing my Django portfolio when I bumped into a problem when choosing a photo for one of the pages of my site The problem here i...
Collapse
 
perigk profile image
Periklis Gkolias •

I am not in front of a computer but I would start with docs.djangoproject.com/en/2.2/ref/...

Collapse
 
highcenburg profile image
Vicente G. Reyes •

What I'm trying to do is I'm trying to upload images from the admin and access it thru this dropdown(seen on the video/photo) but when I click it, it does not show anything.

Collapse
 
perigk profile image
Periklis Gkolias •

What do the logs say? I am afraid I cannot help with guessing. :)

Thread Thread
 
highcenburg profile image
Vicente G. Reyes • • Edited

When I use this

image = models.FileField(upload_to='static/')
it returns a
Server Error (500)
on the admin.


When I use
image = models.FileField("/img")
It return a
Server Error (500)
on the site.

When I use
models.FilePathField(path=os.path.join(settings.BASE_DIR, 'home/projects/static/img'))
it returns a
Server Error (500)
on the admin.

Im confused. I just want to upload images from the admin to the portfolio page of my site.
Thread Thread
 
perigk profile image
Periklis Gkolias •

As explained a couple of times above, those are generic errors and without more specific info or code I am afraid I cannot be of much help, if my only weapon is guessing.

There are various tutorials online. Please have a look and if you have any specific questions please ask again.

A great tutorial that will help: wsvincent.com/django-image-uploads/

Collapse
 
highcenburg profile image
Vicente G. Reyes •

Great! I've been wondering what I was missing on my code to upload files from the admin. Will check this the first thing tomorrow. Cheers!

Collapse
 
highcenburg profile image
Vicente G. Reyes •

Hey Rhett,

Thank you for this. I'm doing a tutorial now and the guy used ImageField which made sense in what I was trying to achieve.

The debug on my project is set to False and the ALLOWED_HOST is set to my localhost. I think the error might be inside the FilePathField line of code. When I use

 image = models.FilePathField(path=os.path.join(settings.BASE_DIR, 'home/projects/static/img'))
it returns the 500 error on the project page, but when I use
image = models.FileField(upload_to='uploads/')
it runs as smooth as silk.

The MEDIA_ROOT & MEDIA_URL would be set now thanks to you.

Cheers!

Collapse
 
fiyinanne profile image
Fiyinfoluwa Akinsiku •

Hi! I am currently working on this same project and I have the same issue. I've searched the internet (how I found this post) but couldn't get a clear solution. How did you resolve it? Thanks.

Collapse
 
highcenburg profile image
Vicente G. Reyes •

Could you post your code?

Collapse
 
romko97 profile image
Roman Halychanivkyi •

I have the same problem if you figured out how to solve that, please write to me.

Collapse
 
highcenburg profile image
Vicente G. Reyes •

Hi, can you post your code?