In the previous section it was seen that, default_profile.png file was not visible even when the file exists in the path. This is because django doesn't serve media files by default.
In order to manually serve the media files during development, you can add the following code inside the projects urls.py
file.
Edit the CampusConnect/urls.py
as follows :
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
This code will allow it to server files present in the MEDIA_ROOT
path.
NOTE : Here it is added inside an if condition as media files should not be served like this in production. During production media files would be served directly by the server on which the code is running and not by Django.
Now, when you visit the url, you will able to view the image stored in that path. Let's start with the work for which this project is created. You will see how you can create events and display them on the website in the further sections.