Django as an API.

pip install virtualenvvirtualenv venv //this second part is where you can name your environment, name it anything you want. I just prefer venvsource venv/bin/activate //this is the command to activate the virtual environment. The command is different depending on mac or windows so always check.
pip install djangodjango-admin startproject backend //again the project name can be whatever you want. If I use it for a backend, that's what I prefer to call it.
python startapp todopython migratepython runserver
from django.db import models# Create your models here.class Todo(models.Model):
title = models.CharField(max_length=120)
description = models.TextField()
def _str_(self):
return self.title
python makemigrationspython migrate
from django.contrib import adminfrom .models import *# Register your models
python createsuperuser
pip install djangorestframework django-cors-headers
from rest_framework import serializers
from .models import Todo

class TodoSerializer(serializers.ModelSerializer):
class Meta:
model = Todo
fields = ('id', 'title', 'description')
from django.shortcuts import render
from rest_framework import viewsets
from .serializers import TodoSerializer
from .models import Todo

# Create your views here.

class TodoView(viewsets.ModelViewSet):
serializer_class = TodoSerializer
queryset = Todo.objects.all()
from django.contrib import admin
from django.urls import path, include
from rest_framework import routers
from todo import views

router = routers.DefaultRouter()
router.register(r'todos', views.TodoView, 'todo')

urlpatterns = [
path('api/', include(router.urls)),



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store