This repo is created for my personal reference to create a restful api project using django. If you find it helpful then it's good.
-
pip install django djangorestframework markdown django-filter
- Go to folder where you want the project to be and run:
django-admin startproject {project-name}
- In
settings.py
, addINSTALLED_APPS = [ ... 'rest_framework', ]
-
Go to the project directory and run:
python manage.py startapp {app-name}
-
In
settings.py
in the main app folder, addINSTALLED_APPS = [ ... '{app-name}.apps.ApiConfig', ]
-
In the app folder, create
urls.py
file. -
In
urls.py
in the main app folder, addurlpatterns = [ ... path('{name-of-the-slug}/', include('{app-name}.urls')) ]
- Create project
django-admin startproject {project-name}
- Run server
python manage.py runserver
- Migrate data
python manage.py migrate
- Create migration
python manage.py makemigrations
- Create admin account
python manage.py createsuperuser
-
In
settings.py
add this (rid the default one)DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'razaknews', 'USER': 'root', 'PASSWORD': '', 'HOST': 'localhost', 'PORT': '3306', 'OPTIONS': { 'sql_mode': 'traditional', } } }
-
In
Models.py
, make sure the models have the same attributes and types with the database. -
To migrate when the table already exist, run
python manage.py migrate --fake {table-name}