🍔 Django with a Side of JavaScript 🍟
Posted on Nov 16th, 2021
🗓️ Today’s Topics
- Progress report on Code Snippets and Flashcards
- Incorporating JavaScript in a Django application
🎯 Project: Code Snippets | Flashcards
Still working on your project. (っ^з^)♪♬
Where you should be with Flashcards today
A logged in user should be able to see a list of all the decks, see the cards in a given deck (after it is selected from the list, for instance), and see the question and answer on a given card. The forms for creating a deck and creating cards for a deck should be done by now. You should be working on marking a card as answered, correctly or incorrectly, and be able to record that data somewhere. If decks belong to one user and are not shared, then you could record this on your deck, but it’s up to you how you model this.
Where you should be with Code Snippets today
A logged in user should be able to see a list of all public snippets and a list of their own snippets, to create new snippets, and to edit and delete existing snippets. You should have a way to manage copying snippets on the back end at least. You may also be ready to start implementing syntax highlighting with JS by this afternoon or evening.
🔖 Resources
Debugging while you work
Setting a breakpoint can help you figure out what code you need in your views!
JavaScript & Django
- Django and AJAX
- Fetching Data with Ajax and Django -> This article is really helpful and has really good code examples. Important notes:
By including the ‘X-Requested-With’ header set to ‘XMLHttpRequest’ [in the AJAX request], the view will be able to check if the request is AJAX or not.
- Django docs on the above
- Working with AJAX in Django
- MDN: Using Fetch Remember JS? 🥴 Here’s a refresher on using Fetch.
- Django CSRF with AJAX
⭐ EXTRA/TMI
- Django Views the Right Way This is a detailed, informative deep dive on function-based views in Django and the reasons why, in the author’s opinion, they are better than class-based views.
- jQuery This is not something I recommend using right now, but I include it here because a lot of the resources about using JavaScript in a web browser refer to it (several of the articles above do). It is not as popular as it once was, and it is incompatible with a framework like React. But you will sometimes come across it, and you may end up working with it at your job, so you might as well recognize it when you see it and look it up if you ever need it.