Web Development with Django by Ben Shaw | Saurabh Badhwar | Chris Guest | Bharath Chandra K S

Web Development with Django by Ben Shaw | Saurabh Badhwar | Chris Guest | Bharath Chandra K S

Author:Ben Shaw | Saurabh Badhwar | Chris Guest | Bharath Chandra K S
Language: eng
Format: epub
Publisher: Packt Publishing Pvt Ltd
Published: 2023-04-25T00:00:00+00:00


Then, add the following code right after your urlpatterns definition (refer to the code block in the previous step) to conditionally add a mapping from the MEDIA_URL setting to the static view, which will serve from MEDIA_ROOT: if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

You can now save this file. It should look like this: https://raw.githubusercontent.com/PacktPublishing/Web-Development-with-Django-Second-Edition/main/Chapter08/Exercise8.01/media_project/media_project/urls.py.

Start the Django dev server, if it is not already running, then visit http://127.0.0.1:8000/media/test.txt. If you did everything correctly, you should see the Hello, world! text in your browser:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.