Django Show Imagefield
I have extended the base User from Django with the OneToOne method. class Employee(models.Model): user = models.OneToOneField(User, on_delete = models.CASCADE) floor = mod
Solution 1:
You should not use
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
to do this. This is okay only for debug purposes. Otherwise, it's your nginx/apache/other_server that should be responsible for serving static files and media files along with routing the .sock file generated by gunicorn/uwsgi.
Solution 2:
I finally figured out how to make it work, so just in case somebody else has the same problem I am going to answer to my question. Basically just add this to settings.py
MEDIA_URL = '/media/'MEDIA_ROOT = os.path.join(BASE_DIR, 'app/media')
And this to urls.py:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Post a Comment for "Django Show Imagefield"