Django is a popular backend framework to develop a web services. This Project aims to provide a clear skeleton for anyone to start a django project.
It will provide a clear project structure with a bunch of the common backend modules including the
Request Middlewares
,Log Parser
,Params Validators
,Session Handle
,Response
Custom Exception Handling
.
+-- api
| +-- user
| | +-- forms.py
| | +-- views.py
| +-- echo
| | +-- forms.py
| | +-- views.py
| +-- {module in the futures}
| | +-- forms.py
| | +-- views.py
| +-- urls.py
+-- doc
+-- scripts
| +-- management
| | +-- commands
| | | +-- {command}.py
+-- service
| +-- biz
| | +-- user
| | | +-- models.py
| | | +-- handler.py
| | | +-- dao.py
| +-- django_ext
| +-- libs
+-- tests
+-- webservices
api
: The api folder contains theurls.py
and a list of business modules view layers. In each modules, there should ba aforms.py
to define the request and responseschema
doc
: To put Documents(api.doc, tech_design.doc etc...)script
: The scripts folder contains Django command scripts.service
: The core business logic. The service folder containslibs
: common utility for the project such asdecorator
,custom exception
,log parser
django_ext
: extend and enhance django utils such asmodels
,response
,view
biz
: for the actual business service logic. In each modules, there are modules as belows(from bottom-up)models.py
: Define db and all the modelsdao.py
: The interface to the databasehandler.py
: business logic
tests
: To put test scriptwebservices
: The webservices contains configuration, middleware and settings.py
The overall flow should be api -> handler -> dao -> model. We should keep the structure and make the project well organized.
- Install docker and docker-compose: Please follow the instruction here. Docker Installation
- Run the project with docker-compose
> cd <path to project>
> docker-compose up
- Test the echo API
> curl --location --request GET 'localhost:8000/api/echo/?echo=echo' \
--header 'Cookie: sessionid=nr4jtmcqd295al1j9w2vxprkng2u49ts'
{"status": "ok", "msg": "", "data": {"echo": {"echo": "echo"}}}%