A few things to prepare the Django API for the combined workspace.
Next, we need to adjust the Django API part of the project to create some new settings and remove code that was required when the projects were in separate repositories.
If you have not deployed your DRF project yet, you will need to create an ElephantSQL database instance and make migrations into it. If you need a reminder on how to do this, the steps can be found in the deployment section of the Django REST Framework module in the LMS.
If you have already deployed your DRF project to Heroku, you will already have an ElephantSQL Postgres database and can continue to the next section.
In your env.py file, make the following changes:
Comment out the DEV environment variable. This ensures that the application will respond with JSON
Remove the CLIENT_ORIGIN_DEV environment variable, if you have it
Add a new key DEBUG with a value of ‘1’
This will allow you to see Djangos logs in the terminal while keeping your JSON responses and will give you a clearer view of errors for debugging across the two parts of the project.
Add a new key ALLOWED_HOST with the value of your development environment URL, wrapped in quotes
Ensure you remove the https:// from the beginning, and the trailing slash / from the end of the development environment URL.
Add a new key CLIENT_ORIGIN with the value of your development environment URL, wrapped in quotes
This string should include the https:// at the beginning, but the trailing slash / should be removed.
Ensure you have a key for DATABASE_URL set to the value of your ElephantSQL database URL
Ensure you have a key for CLOUDINARY_URL set to the value of your Cloudinary URL
If you are working in Codeanywhere you will need to install the urllib3 package to ensure your post images will save to Cloudinary without errors.
Ensure your terminal location is in the root directory, then install urllib3 with the following command
pip3 install urllib3==1.26.15
Add this dependency to your requirements.txt file with the following command
pip3 freeze > requirements.txt
We must update a few things in the settings of our Django application, we will take you through those next.