Hello all! I’m working on a personal project and I’m running into 2 errors which occur at the same spot in my code.
#1: Division by zero: This error is caused because I’m sending a paragraph of data from the frontend to the backend and it’s not arriving. Since it never arrives, the numbers are null and it tries to divide null by zero. (This error happens sometimes on my local machine, but every time on Heroku.)
#2: CSRF: I’m trying to protect the second API endpoint using CSRF, but I’m not quite sure how to do it. This might be effecting the first error.
Project:
Online version:
https://songfeels.herokuapp.com
Pseudocode:
-User searches for song. File: components/Main.js on frontend.
-class SongView get() runs a query on api, sends back lyrics. File: backend/views.py on backend.
-Page renders a list of songs. File: components/SearchResults.js on frontend.
-User chooses a song to analyze. axios.post sends the original_lyrics. File: components/Main.js again on frontend.
(This is where both errors are causing problems)
-class AnalyzeView post() should storerequest.body.decode data as post_data. Sometimes it works, sometimes it doesn’t. File: backend/views.py again on backend.
Any suggestions how to fix either problem?