advfe-unified-workspace

Advanced Front End: Preparing the Django API for development

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.

Preparing your Database

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.

Preparing your Environment Variables

In your env.py file, make the following changes:

  1. Comment out the DEV environment variable. This ensures that the application will respond with JSON

  2. Remove the CLIENT_ORIGIN_DEV environment variable, if you have it

  3. 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.

  4. 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.

  5. 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.

  6. Ensure you have a key for DATABASE_URL set to the value of your ElephantSQL database URL

  7. Ensure you have a key for CLOUDINARY_URL set to the value of your Cloudinary URL

    an env.py file with an environment variable for cloudinary_url

Install urllib3

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.

  1. Ensure your terminal location is in the root directory, then install urllib3 with the following command

    pip3 install urllib3==1.26.15

  2. Add this dependency to your requirements.txt file with the following command

    pip3 freeze > requirements.txt

Up Next

We must update a few things in the settings of our Django application, we will take you through those next.