├── .gitignore ├── Pipfile ├── Pipfile.lock ├── README.md └── api ├── api ├── __init__.py ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py ├── languages ├── __init__.py ├── admin.py ├── apps.py ├── migrations │ ├── 0001_initial.py │ ├── 0002_auto_20200501_1615.py │ └── __init__.py ├── models.py ├── serializers.py ├── tests.py ├── urls.py └── views.py └── manage.py /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/django,python 3 | # Edit at https://www.gitignore.io/?templates=django,python 4 | 5 | ### Django ### 6 | *.log 7 | *.pot 8 | *.pyc 9 | __pycache__/ 10 | local_settings.py 11 | db.sqlite3 12 | db.sqlite3-journal 13 | media 14 | 15 | # If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/ 16 | # in your Git repository. Update and uncomment the following line accordingly. 17 | # /staticfiles/ 18 | 19 | ### Django.Python Stack ### 20 | # Byte-compiled / optimized / DLL files 21 | *.py[cod] 22 | *$py.class 23 | 24 | # C extensions 25 | *.so 26 | 27 | # Distribution / packaging 28 | .Python 29 | build/ 30 | develop-eggs/ 31 | dist/ 32 | downloads/ 33 | eggs/ 34 | .eggs/ 35 | lib/ 36 | lib64/ 37 | parts/ 38 | sdist/ 39 | var/ 40 | wheels/ 41 | pip-wheel-metadata/ 42 | share/python-wheels/ 43 | *.egg-info/ 44 | .installed.cfg 45 | *.egg 46 | MANIFEST 47 | 48 | # PyInstaller 49 | # Usually these files are written by a python script from a template 50 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 51 | *.manifest 52 | *.spec 53 | 54 | # Installer logs 55 | pip-log.txt 56 | pip-delete-this-directory.txt 57 | 58 | # Unit test / coverage reports 59 | htmlcov/ 60 | .tox/ 61 | .nox/ 62 | .coverage 63 | .coverage.* 64 | .cache 65 | nosetests.xml 66 | coverage.xml 67 | *.cover 68 | .hypothesis/ 69 | .pytest_cache/ 70 | 71 | # Translations 72 | *.mo 73 | 74 | # Scrapy stuff: 75 | .scrapy 76 | 77 | # Sphinx documentation 78 | docs/_build/ 79 | 80 | # PyBuilder 81 | target/ 82 | 83 | # pyenv 84 | .python-version 85 | 86 | # pipenv 87 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 88 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 89 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 90 | # install all needed dependencies. 91 | #Pipfile.lock 92 | 93 | # celery beat schedule file 94 | celerybeat-schedule 95 | 96 | # SageMath parsed files 97 | *.sage.py 98 | 99 | # Spyder project settings 100 | .spyderproject 101 | .spyproject 102 | 103 | # Rope project settings 104 | .ropeproject 105 | 106 | # Mr Developer 107 | .mr.developer.cfg 108 | .project 109 | .pydevproject 110 | 111 | # mkdocs documentation 112 | /site 113 | 114 | # mypy 115 | .mypy_cache/ 116 | .dmypy.json 117 | dmypy.json 118 | 119 | # Pyre type checker 120 | .pyre/ 121 | 122 | ### Python ### 123 | # Byte-compiled / optimized / DLL files 124 | 125 | # C extensions 126 | 127 | # Distribution / packaging 128 | 129 | # PyInstaller 130 | # Usually these files are written by a python script from a template 131 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 132 | 133 | # Installer logs 134 | 135 | # Unit test / coverage reports 136 | 137 | # Translations 138 | 139 | # Scrapy stuff: 140 | 141 | # Sphinx documentation 142 | 143 | # PyBuilder 144 | 145 | # pyenv 146 | 147 | # pipenv 148 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 149 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 150 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 151 | # install all needed dependencies. 152 | 153 | # celery beat schedule file 154 | 155 | # SageMath parsed files 156 | 157 | # Spyder project settings 158 | 159 | # Rope project settings 160 | 161 | # Mr Developer 162 | 163 | # mkdocs documentation 164 | 165 | # mypy 166 | 167 | # Pyre type checker 168 | 169 | # End of https://www.gitignore.io/api/django,python -------------------------------------------------------------------------------- /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | name = "pypi" 3 | url = "https://pypi.org/simple" 4 | verify_ssl = true 5 | 6 | [dev-packages] 7 | 8 | [packages] 9 | djangorestframework = "*" 10 | 11 | [requires] 12 | python_version = "3.7" 13 | -------------------------------------------------------------------------------- /Pipfile.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_meta": { 3 | "hash": { 4 | "sha256": "a02d97518868443fc1c6b2baefed98d99f9615d3a7fd9565847390c8b0819182" 5 | }, 6 | "pipfile-spec": 6, 7 | "requires": { 8 | "python_version": "3.7" 9 | }, 10 | "sources": [ 11 | { 12 | "name": "pypi", 13 | "url": "https://pypi.org/simple", 14 | "verify_ssl": true 15 | } 16 | ] 17 | }, 18 | "default": { 19 | "asgiref": { 20 | "hashes": [ 21 | "sha256:8036f90603c54e93521e5777b2b9a39ba1bad05773fcf2d208f0299d1df58ce5", 22 | "sha256:9ca8b952a0a9afa61d30aa6d3d9b570bb3fd6bafcf7ec9e6bed43b936133db1c" 23 | ], 24 | "version": "==3.2.7" 25 | }, 26 | "django": { 27 | "hashes": [ 28 | "sha256:642d8eceab321ca743ae71e0f985ff8fdca59f07aab3a9fb362c617d23e33a76", 29 | "sha256:d4666c2edefa38c5ede0ec1655424c56dc47ceb04b6d8d62a7eac09db89545c1" 30 | ], 31 | "version": "==3.0.5" 32 | }, 33 | "djangorestframework": { 34 | "hashes": [ 35 | "sha256:05809fc66e1c997fd9a32ea5730d9f4ba28b109b9da71fccfa5ff241201fd0a4", 36 | "sha256:e782087823c47a26826ee5b6fa0c542968219263fb3976ec3c31edab23a4001f" 37 | ], 38 | "index": "pypi", 39 | "version": "==3.11.0" 40 | }, 41 | "pytz": { 42 | "hashes": [ 43 | "sha256:a494d53b6d39c3c6e44c3bec237336e14305e4f29bbf800b599253057fbb79ed", 44 | "sha256:c35965d010ce31b23eeb663ed3cc8c906275d6be1a34393a1d73a41febf4a048" 45 | ], 46 | "version": "==2020.1" 47 | }, 48 | "sqlparse": { 49 | "hashes": [ 50 | "sha256:022fb9c87b524d1f7862b3037e541f68597a730a8843245c349fc93e1643dc4e", 51 | "sha256:e162203737712307dfe78860cc56c8da8a852ab2ee33750e33aeadf38d12c548" 52 | ], 53 | "version": "==0.3.1" 54 | } 55 | }, 56 | "develop": {} 57 | } 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Django REST API 2 | 3 | ## Description 4 | 5 | This repository is a Software of Application with Python, Django, etc. 6 | 7 | ## Installation 8 | 9 | Using Django, djangorestframework,etc preferably. 10 | 11 | ## DataBase 12 | 13 | Using SQLite3 preferably. 14 | 15 | ## Apps 16 | 17 | Using pipenv. 18 | 19 | ## Usage 20 | 21 | ```html 22 | $ git clone https://github.com/DanielArturoAlejoAlvarez/django-rest-api.git 23 | [NAME APP] 24 | ``` 25 | 26 | Follow the following steps and you're good to go! Important: 27 | 28 | ![alt text](https://camo.githubusercontent.com/63cff5254d7b948dea095696bc62092b2379f29f/68747470733a2f2f7261772e6769746875622e636f6d2f69637963616e646c652f7375626c696d652d646a616e676f2d6c6f6f6b75702f6d61737465722f64656d6f2e676966) 29 | 30 | ## Coding 31 | 32 | ### Models 33 | 34 | ```python 35 | ... 36 | from django.db import models 37 | 38 | class Language(models.Model): 39 | name = models.CharField(max_length=100) 40 | paradigm = models.CharField(max_length=128) 41 | 42 | def __str__(self): 43 | return self.name 44 | ... 45 | ``` 46 | 47 | ### Controllers 48 | 49 | ```python 50 | ... 51 | from rest_framework import serializers 52 | from .models import Language 53 | 54 | class LanguageSerializer(serializers.HyperlinkedModelSerializer): 55 | class Meta: 56 | model = Language 57 | fields = ('id','url','name','paradigm') 58 | ... 59 | ``` 60 | 61 | ### Views 62 | 63 | ```python 64 | ... 65 | from django.shortcuts import render 66 | from rest_framework import viewsets 67 | 68 | from .models import Language 69 | from .serializers import LanguageSerializer 70 | 71 | class LanguageView(viewsets.ModelViewSet): 72 | queryset = Language.objects.all() 73 | serializer_class = LanguageSerializer 74 | 75 | ... 76 | ``` 77 | 78 | ### Routes 79 | 80 | ```python 81 | ... 82 | from django.urls import path,include 83 | 84 | from . import views 85 | from rest_framework import routers 86 | 87 | router = routers.DefaultRouter() 88 | router.register('languages', views.LanguageView) 89 | 90 | urlpatterns = [ 91 | path('', include(router.urls)) 92 | ] 93 | ... 94 | ``` 95 | 96 | ## Contributing 97 | 98 | Bug reports and pull requests are welcome on GitHub at https://github.com/DanielArturoAlejoAlvarez/django-rest-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. 99 | 100 | ## License 101 | 102 | The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). 103 | ```` 104 | -------------------------------------------------------------------------------- /api/api/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielArturoAlejoAlvarez/django-rest-api/4656b1a9e1778d2a6a4e726e445a76580bf9d04e/api/api/__init__.py -------------------------------------------------------------------------------- /api/api/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for api project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /api/api/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for api project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.0.5. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.0/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = '55&ckkhfr2lhdmuxat7yk=!m3(#76w%&vq-e(u(@mrit#6b4qk' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'rest_framework', 41 | 'languages' 42 | ] 43 | 44 | MIDDLEWARE = [ 45 | 'django.middleware.security.SecurityMiddleware', 46 | 'django.contrib.sessions.middleware.SessionMiddleware', 47 | 'django.middleware.common.CommonMiddleware', 48 | 'django.middleware.csrf.CsrfViewMiddleware', 49 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 50 | 'django.contrib.messages.middleware.MessageMiddleware', 51 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 52 | ] 53 | 54 | ROOT_URLCONF = 'api.urls' 55 | 56 | TEMPLATES = [ 57 | { 58 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 59 | 'DIRS': [], 60 | 'APP_DIRS': True, 61 | 'OPTIONS': { 62 | 'context_processors': [ 63 | 'django.template.context_processors.debug', 64 | 'django.template.context_processors.request', 65 | 'django.contrib.auth.context_processors.auth', 66 | 'django.contrib.messages.context_processors.messages', 67 | ], 68 | }, 69 | }, 70 | ] 71 | 72 | WSGI_APPLICATION = 'api.wsgi.application' 73 | 74 | 75 | # Database 76 | # https://docs.djangoproject.com/en/3.0/ref/settings/#databases 77 | 78 | DATABASES = { 79 | 'default': { 80 | 'ENGINE': 'django.db.backends.sqlite3', 81 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 82 | } 83 | } 84 | 85 | 86 | # Password validation 87 | # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators 88 | 89 | AUTH_PASSWORD_VALIDATORS = [ 90 | { 91 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 92 | }, 93 | { 94 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 95 | }, 96 | { 97 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 98 | }, 99 | { 100 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 101 | }, 102 | ] 103 | 104 | 105 | # Internationalization 106 | # https://docs.djangoproject.com/en/3.0/topics/i18n/ 107 | 108 | LANGUAGE_CODE = 'en-us' 109 | 110 | TIME_ZONE = 'UTC' 111 | 112 | USE_I18N = True 113 | 114 | USE_L10N = True 115 | 116 | USE_TZ = True 117 | 118 | 119 | # Static files (CSS, JavaScript, Images) 120 | # https://docs.djangoproject.com/en/3.0/howto/static-files/ 121 | 122 | STATIC_URL = '/static/' 123 | -------------------------------------------------------------------------------- /api/api/urls.py: -------------------------------------------------------------------------------- 1 | """api URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path,include 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | path('', include('languages.urls')) 22 | ] 23 | -------------------------------------------------------------------------------- /api/api/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for api 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/3.0/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', 'api.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /api/languages/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielArturoAlejoAlvarez/django-rest-api/4656b1a9e1778d2a6a4e726e445a76580bf9d04e/api/languages/__init__.py -------------------------------------------------------------------------------- /api/languages/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Language 3 | 4 | admin.site.register(Language) 5 | -------------------------------------------------------------------------------- /api/languages/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class LanguagesConfig(AppConfig): 5 | name = 'languages' 6 | -------------------------------------------------------------------------------- /api/languages/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.5 on 2020-05-01 15:48 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | initial = True 9 | 10 | dependencies = [ 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Language', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('name', models.CharField(max_length=100)), 19 | ('paradig', models.CharField(max_length=128)), 20 | ], 21 | ), 22 | ] 23 | -------------------------------------------------------------------------------- /api/languages/migrations/0002_auto_20200501_1615.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.5 on 2020-05-01 16:15 2 | 3 | from django.db import migrations 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('languages', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RenameField( 14 | model_name='language', 15 | old_name='paradig', 16 | new_name='paradigm', 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /api/languages/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielArturoAlejoAlvarez/django-rest-api/4656b1a9e1778d2a6a4e726e445a76580bf9d04e/api/languages/migrations/__init__.py -------------------------------------------------------------------------------- /api/languages/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | class Language(models.Model): 4 | name = models.CharField(max_length=100) 5 | paradigm = models.CharField(max_length=128) 6 | 7 | def __str__(self): 8 | return self.name -------------------------------------------------------------------------------- /api/languages/serializers.py: -------------------------------------------------------------------------------- 1 | from rest_framework import serializers 2 | from .models import Language 3 | 4 | class LanguageSerializer(serializers.HyperlinkedModelSerializer): 5 | class Meta: 6 | model = Language 7 | fields = ('id','url','name','paradigm') -------------------------------------------------------------------------------- /api/languages/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /api/languages/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path,include 2 | 3 | from . import views 4 | from rest_framework import routers 5 | 6 | router = routers.DefaultRouter() 7 | router.register('languages', views.LanguageView) 8 | 9 | urlpatterns = [ 10 | path('', include(router.urls)) 11 | ] -------------------------------------------------------------------------------- /api/languages/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from rest_framework import viewsets 3 | 4 | from .models import Language 5 | from .serializers import LanguageSerializer 6 | 7 | class LanguageView(viewsets.ModelViewSet): 8 | queryset = Language.objects.all() 9 | serializer_class = LanguageSerializer 10 | 11 | -------------------------------------------------------------------------------- /api/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | --------------------------------------------------------------------------------