But an API doesn't care about that: it's only raw data at endpoints, which means JSON, and accompanying HTTP verbs that tell the API what actions can be taken (more on this shortly).Ĭreate a new snippets/serializers.py file and update it as follows. Consider that the end result of a traditional website is a page of HTML, CSS, and content from the database. This the real "magic" that Django Rest Framework provides for us. Both will be visible on the main Snippets page.Ī Serializer transforms model instances into JSON. And create two new snippets.Ĭlick the "Save" button in the lower right for each snippet. Log in with your superuser account.Ĭlick on the "+ Add" button next to Snippets. Navigate over to the Django homepage at to confirm everything is working. That's what we'll do here.Įnter the following commands in your terminal: One option is the Desktop whether you are on a Windows or Mac computer. This can live anywhere on your computer but in a location that is easily accessible. Once that's done, create a dedicated directory for our code and set up a new Python virtual environment. If you need help with this, go to Chapter 1: Set Up of the Django for APIs book for a step-by-step guide to configuring your computer for Django development. You will need to have the latest version of Python installed on your computer. The first few chapters are available for free. NOTE: If you'd like to learn even more about APIs in Django, I've written an entire book on the subject, Django for APIs. However I provide more detailed explanations of each step, use the Django admin rather than the Django shell for populating the models, emphasize class-based views over function-based views, and so on.Īfter completing this tutorial, the official tutorial should make a lot more sense and help you take full advantage of the awesomeness that is Django REST Framework. The final code is exactly the same and is available on GitHub. If you have struggled to complete the official tutorial on your own, consider this guide a good place to start instead. This is a beginner-friendly guide to the official Django Rest Framework tutorial that works for both Windows and macOS. Official Django REST Framework Tutorial - A Beginners Guide
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |