Scaffold Django APIs like a champion
3 min read

Scaffold Django APIs like a champion

Scaffold Django APIs like a champion
Photo by Owen Lystrup / Unsplash

scaffold django api application with command line

Hey 👋 my name is Abdenasser I'll give you a proper introduction to who I'm in the next blog, but today I'll show you how to use this little Django scaffold library I crafted last week to create a ready to use and fully functional REST APIs with Django only using the command line, let's get started.

Setting a Django environment is outside of the scope of this article, I'm sure there's a lot of guides and tutorials on how to do that all over the internet you can follow one of them and get back, I'll be waiting for you just right here!

In a nutshell here is what we gonna do in three steps:

  1. Create a Django project
  2. Setup Django rest framework and dr_scaffold
  3. Scaffold a blog API with Articles and Authors

1. Create a Django project:

Let's create a Django project using this django-admin command:

$ django-admin startproject myApi

this command does the same as python startproject myApi the only difference is that it doesn't require a python environment to get executed.

Let's then cd to our newly created Django project cd myApi and create a virtualenv with:

$ python3 -m virtualenv env

Finally let's activate our virtual env with:

$ source env/bin/activate

2. Setup Django rest framework and dr_scaffold:

Let's install Django rest framework and dr_scaffold packages using pip like the following:

$ pip install djangorestframework
$ pip install dr-scaffold

Next let's add these packages to our project INSTALLED_APPS inside myApi/ like this:


Then let's add our core and API folders settings to myApi/, (for the simplicity of the tutorial we'll leave them empty):

CORE_FOLDER = ""  # you can leave them empty
API_FOLDER = ""   # or set them to be the same

3. Scaffold a blog API with Articles and Authors

Our blog API will be composed of two main resources an Article and a Author, Let's scaffold our Author first:

$ python dr_scaffold blog Author name:charfield
🎉 Your RESTful Author api resource is ready 🎉

this command will generate a blog folder with > all populated with appropriate code that your REST API needs for Author resource

Lets also generate the Article resource:

$ python dr_scaffold blog Post body:textfield author:foreignkey:Author
🎉 Your RESTful Post api resource is ready 🎉

this command will do the same thing but also will add a relation to our Author resource through a foreignkey field.

In order to generate the database tables let's add blog to our INSTALLED_APPS inside myApi/


Then let's run these commands to generate our migrations and migrate the database:

$ python makemigrations
$ python migrate

Finally add our blog to our project's urlpatterns inside myApi/

urlpatterns = [
    path("blog/", include("blog.urls")),

Don't forget to import include in your project's like so :

from django.conf.urls import include

Your should look something like this in the end:

from django.conf.urls import include #our added import
from django.contrib import admin
from django.urls import path

urlpatterns = [
    path("blog/", include("blog.urls")), #our added bol path

Now that we are completely done let's run python runserver and head over to to see your fully created REST blog API.. and also you can generate a super user with python createsuperuser then head over to to check the admin panel.

Don't forget to star the repo on GitHub If you like it.. Enjoy 🎉 !

GitHub - Abdenasser/dr_scaffold: scaffold django rest apis like a champion 🚀
scaffold django rest apis like a champion 🚀. Contribute to Abdenasser/dr_scaffold development by creating an account on GitHub.