├── .gitignore ├── LICENSE ├── README.md ├── manage.py ├── microservice ├── __init__.py ├── models.py ├── serializers.py ├── settings.py ├── urls.py ├── views.py └── wsgi.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | *.sqlite3 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # IPython Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # dotenv 80 | .env 81 | 82 | # virtualenv 83 | venv/ 84 | ENV/ 85 | 86 | # Spyder project settings 87 | .spyderproject 88 | 89 | # Rope project settings 90 | .ropeproject 91 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Alberto Casero 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Django Microservice Template 2 | A Django project template for microservices. 3 | 4 | ## How to install 5 | 6 | Create a new project based on this template using: 7 | 8 | ``` 9 | $ django-admin.py startproject \ 10 | --template=https://github.com/kasappeal/django-microservice/archive/master.zip \ 11 | --extension=py,txt \ 12 | project_name 13 | ``` 14 | 15 | Install virtualenv dependencies using: 16 | 17 | ``` 18 | $ pip install -r requirements.txt 19 | ``` -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "microservice.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError: 10 | # The above import may fail for some other reason. Ensure that the 11 | # issue is really that Django is missing to avoid masking other 12 | # exceptions on Python 2. 13 | try: 14 | import django 15 | except ImportError: 16 | raise ImportError( 17 | "Couldn't import Django. Are you sure it's installed and " 18 | "available on your PYTHONPATH environment variable? Did you " 19 | "forget to activate a virtual environment?" 20 | ) 21 | raise 22 | execute_from_command_line(sys.argv) 23 | -------------------------------------------------------------------------------- /microservice/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kasappeal/django-microservice/086fc0cb8982aa1d4777941d56cc9d4a91303ac3/microservice/__init__.py -------------------------------------------------------------------------------- /microservice/models.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from django.db import models 3 | 4 | # TODO: write here your models 5 | -------------------------------------------------------------------------------- /microservice/serializers.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from rest_framework import serializers 3 | 4 | # TODO: write here your model serializers 5 | -------------------------------------------------------------------------------- /microservice/settings.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 4 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 5 | 6 | 7 | # Quick-start development settings - unsuitable for production 8 | # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ 9 | 10 | # SECURITY WARNING: keep the secret key used in production secret! 11 | SECRET_KEY = '****************************************** SET HERE YOUR SECRET *****************************************' 12 | 13 | # SECURITY WARNING: don't run with debug turned on in production! 14 | DEBUG = True 15 | 16 | ALLOWED_HOSTS = [] 17 | 18 | 19 | # Application definition 20 | 21 | INSTALLED_APPS = [ 22 | 'django.contrib.staticfiles', 23 | 'rest_framework', 24 | 'microservice' 25 | ] 26 | 27 | MIDDLEWARE = [ 28 | 'django.middleware.security.SecurityMiddleware', 29 | 'django.middleware.common.CommonMiddleware', 30 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 31 | ] 32 | 33 | ROOT_URLCONF = 'microservice.urls' 34 | 35 | TEMPLATES = [ 36 | { 37 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 38 | 'DIRS': [], 39 | 'APP_DIRS': True, 40 | 'OPTIONS': { 41 | 'context_processors': [ 42 | 'django.template.context_processors.debug', 43 | 'django.template.context_processors.request', 44 | ], 45 | }, 46 | }, 47 | ] 48 | 49 | WSGI_APPLICATION = 'microservice.wsgi.application' 50 | 51 | 52 | # Database 53 | # https://docs.djangoproject.com/en/1.11/ref/settings/#databases 54 | 55 | DATABASES = { 56 | 'default': { 57 | 'ENGINE': 'django.db.backends.sqlite3', 58 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 59 | } 60 | } 61 | 62 | 63 | # Internationalization 64 | # https://docs.djangoproject.com/en/1.11/topics/i18n/ 65 | 66 | LANGUAGE_CODE = 'en-us' 67 | 68 | TIME_ZONE = 'UTC' 69 | 70 | USE_I18N = True 71 | 72 | USE_L10N = True 73 | 74 | USE_TZ = True 75 | 76 | 77 | # Static files (CSS, JavaScript, Images) 78 | # https://docs.djangoproject.com/en/1.11/howto/static-files/ 79 | 80 | STATIC_URL = '/static/' 81 | 82 | REST_FRAMEWORK = { 83 | 'UNAUTHENTICATED_USER': None 84 | } 85 | -------------------------------------------------------------------------------- /microservice/urls.py: -------------------------------------------------------------------------------- 1 | from rest_framework.routers import SimpleRouter 2 | 3 | router = SimpleRouter() 4 | 5 | # TODO: add here your API URLs 6 | 7 | urlpatterns = router.urls 8 | -------------------------------------------------------------------------------- /microservice/views.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # TODO: Write here your API ViewSets 3 | -------------------------------------------------------------------------------- /microservice/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for microservice project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "microservice.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Django==1.11 2 | djangorestframework==3.6.2 3 | --------------------------------------------------------------------------------