Issue
I was trying to upload an image with the ImageField and one I select the image and click save it is throwing an error that the submitted file is empty. error screenshot
models.py
class Gallery(models.Model):
id = models.AutoField(primary_key=True)
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True)
title = models.CharField(max_length=100, null=False)
image = models.ImageField(upload_to='images')
urls.py
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root= settings.MEDIA_ROOT)
Also it has not created a media directory. is it because that I have a directory named media inside my static? media directory i created inside static
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
Checked google for quick fixes.
Solution
I had gone through your code I didn't see any possible error on your code, the only issue you had is that Django gotcha
caught you, you don't recreate or create what Django used in it's internal logic to build your code for example naming your app module auth or auths
, this will cause nuisance/weird behavior in your code.
Kindly do this:
1.Change the name of the file in your static file you named from media to something else.
2. Make sure that you have imported pillow via pip
3. Ensure that your `static` is properly imported from Django conf like below:
from django.conf.urls.static import static
Good luck!
Answered By - Blaisemart
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.