I don’t mean that in the good way. I had a lot of noob problems with this setup. First of all, where is this “don’t repeat yourself” mantra of Django, I ask myself as I am opening up the settings file at moodilyzer/moodilyzer/moodilyzer/settings.py
, and editing my templates at moodilyzer/moodilyzer/nn/templates/nn/index.html
. Someone did not think this motto through.
The next problem is CORS. Mind you I’m not even doing CORS on the deployment server! It’s all coming from the same place. But on my development machine, React wants to be on port 3000, and Django wants to be on port 8000. So they think I’m committing some sort of crime when I want them to play together. I have tried all the various fixes suggested on the internet and none has worked so far, so I am leaving this complaint here as I reminder to myself to post the answer when I find it. I’m sure it’ll be a doozy. My other option is to run npm build and stuff my react code into Django every time I make a change in development, but that really loses all of the slick development machinery that the React folks went to all the trouble to come up with.
What next… jquery ajax POST requests aren’t working. I suspect it is probably how the post data is formatted, because the request goes through as if there were no data. For now I am using GET requests since it is behind the scenes anyway, and I will probably try axios instead since I should be moving on to something more hip than jquery. I mean how gauche.
The real winner here is React-Bootstrap, which allowed me to build a somewhat slick-looking UI. Perhaps ‘slick’ is the wrong word, but let’s say much better than the raw HTML UI I started with! Check out Moodilyzer.js to see how it works. One interesting bit is how to deal with the CSRF token that Django requires. That is accomplished with the getCookie()
function and the X-CSRFToken
header in the ajax call. I got the getCookie()
function from this fellow.