Created
February 5, 2017 09:21
-
-
Save nix1947/5478a5e321f093fb52f7c59f7228f014 to your computer and use it in GitHub Desktop.
Enable media display in django in development server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Enable the media context processor, from settings.py file | |
django.template.context_processors.media | |
2. Set MEDIA_URL and MEDIA_ROOT in settings.py file | |
MEDIA_URL = '/media' | |
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') | |
3. Serve the media from development server in url.py file | |
# Serving media files during development | |
# Can be written this line directly in the development.py settings file | |
if settings.DEBUG: | |
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) | |
4. Load the images in template | |
<img src="{{MEDIA_URL}}{{user.profile_image"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment