Skip to content

Instantly share code, notes, and snippets.

@nix1947
Created February 5, 2017 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nix1947/5478a5e321f093fb52f7c59f7228f014 to your computer and use it in GitHub Desktop.
Save nix1947/5478a5e321f093fb52f7c59f7228f014 to your computer and use it in GitHub Desktop.
Enable media display in django in development server
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