Difference between revisions of "Django"
Adelo Vieira (talk | contribs) |
Adelo Vieira (talk | contribs) (→Setting the development environment) |
||
Line 67: | Line 67: | ||
==Setting the development environment== | ==Setting the development environment== | ||
− | * ''' | + | * '''requirements.txt:''' |
<blockquote> | <blockquote> | ||
<code>requirements.txt:</code> | <code>requirements.txt:</code> | ||
Line 77: | Line 77: | ||
− | + | <br /> | |
− | |||
− | |||
− | + | * '''Dockerfile:''' | |
− | + | <blockquote> | |
− | + | <syntaxhighlight lang="html"> | |
− | |||
− | |||
− | + | </syntaxhighlight> | |
− | + | </blockquote> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | <br /> | ||
+ | * '''.dockerignore:''' | ||
+ | <blockquote> | ||
+ | <syntaxhighlight lang="html"> | ||
− | + | </syntaxhighlight> | |
− | + | </blockquote> | |
− | |||
− | |||
− | |||
− | |||
− | + | <br /> | |
− | app | + | * '''Then we create the app directory insde our project directory''' |
− | + | <blockquote> | |
− | + | <syntaxhighlight lang="html"> | |
− | app | + | mkdir app |
− | + | </syntaxhighlight> | |
− | + | </blockquote> | |
− | |||
− | Then we | + | <br /> |
+ | * '''Then we run:''' | ||
+ | <blockquote> | ||
+ | docker build . | ||
+ | <syntaxhighlight lang="html"> | ||
− | + | </syntaxhighlight> | |
− | + | </blockquote> | |
− | + | <br /> | |
− | + | * '''docker-compose.yml''' | |
+ | <blockquote> | ||
+ | <syntaxhighlight lang="html"> | ||
− | + | </syntaxhighlight> | |
− | + | </blockquote> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | Then we run in our project directory: | + | <br /> |
+ | * '''Then we run in our project directory:''' | ||
+ | <blockquote> | ||
+ | <syntaxhighlight lang="html"> | ||
docker-compose build | docker-compose build | ||
+ | </syntaxhighlight> | ||
+ | </blockquote> | ||
− | + | <br /> | |
− | + | * '''...:''' | |
− | ... | + | <blockquote> |
− | + | <syntaxhighlight lang="html"> | |
− | |||
docker-compose run --rm app sh -c "flake8" | docker-compose run --rm app sh -c "flake8" | ||
− | |||
docker-compose run --rm app sh -c "django-admin startproject app ." | docker-compose run --rm app sh -c "django-admin startproject app ." | ||
− | |||
docker-compose up | docker-compose up | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote> | </blockquote> | ||
− | + | <br /> | |
− | |||
− | |||
− | |||
− | |||
− | </ |
Revision as of 13:28, 5 May 2023
https://www.djangoproject.com/
Contents
Recipe REST API - Udemy course
https://www.udemy.com/course/django-python-advanced/
API Features:
- 19 API Endpoints
- Managing users, recipes, tags, ingredients
- User Authentication
- Browseable Admin Interface (Django Admin)
- Browsable API (Swagger)
Techologies used in this course:
- Django allows handle: URL Mappings / Object Relational Mapper / Admin site
- Django REST Framework: Django add-on / Build REST APIs
- PostgresSQL
- Docker
- Git
- Swagger: Documentation / Browsable API (testing)
Structure of the project:
- app/ : Main app - Django project
- app/core/ : Hangle any code shared between multiple apps. Such as the DB definition using the Django modules
- app/user/ : User related code. Such as User registration & auth tokens
- app/recipe/ : Recipe related code. Such as handling updating ingredients - Creating/Deleting/Udating recipes
Unit Tests and Test-driven development (TDD)
See explanation at https://www.udemy.com/course/django-python-advanced/learn/lecture/32238668#notes
- Unit Tests: Code which test code:
- It's usually done this way:
- You Set up some conditions; such as inputs to a function
- Then you run a piece of code
- Checks outputs of that code using "assertions"
Test-driven development (TDD)
... pegar la imagen de la presentacion que tomé del curso ...
Docker
- Define a Dockerfile: Contains all the OS level dependencies that our project needs.
- Create a Docker Compose configuration: Tells Docker how to run the images that are created from our Docker file configuration.
- Run all commands via Docker Compose.
- Docker on GitHub Actions:
- Docker Hub is where we can pull shared public images to reuse them for your project. For example there an image for Python, PostgreSQL, etc. Docker Hub has introduced rate limits.
- Because of the rate limits, we have to Authenticate with Docker Hub: Create an account / Setup credentials / Login before running job.
- https://hub.docker.com/
Setting the development environment
- requirements.txt:
requirements.txt:
Django>=3.2.4,<3.3 djangorestframework>=3.12.4,<3.13
- Dockerfile:
- .dockerignore:
- Then we create the app directory insde our project directory
mkdir app
- Then we run:
docker build .
- docker-compose.yml
- Then we run in our project directory:
docker-compose build
- ...:
docker-compose run --rm app sh -c "flake8" docker-compose run --rm app sh -c "django-admin startproject app ." docker-compose up