- Sistema: Linux ou macOS (ou Windows com pyenv-win)
- Ferramentas:
git,curl,build-essential(toolchain C) - Gerenciadores:
pyenvevenv
sudo apt update
sudo apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev git
curl https://pyenv.run | bashAdicione ao seu shell:
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"Depois reinicie o terminal ou rode source ~/.bashrc.
pyenv install 3.13.5
pyenv global 3.13.5
python --version # Deve exibir Python 3.13.5python -m venv .venv
source .venv/bin/activate # Linux/macOS
# .venv\Scripts\Activate.ps1 # Windows PowerShellDjango>=4.2
djangorestframework>=3.14
djangorestframework-simplejwt>=5.2
drf-spectacular>=0.28
pytest>=7.0
pytest-django>=4.5
pip install --upgrade pip setuptools wheel
pip install -r requirements.txtpython manage.py makemigrations
python manage.py migratepython manage.py createsuperuserpython manage.py runserverAcesse:
- Admin: http://127.0.0.1:8000/admin/
- API base: http://127.0.0.1:8000/api/
python manage.py testOu, se estiver usando pytest:
pytestbiblioteca_api/
├── manage.py
├── config/
│ ├── settings.py
│ ├── urls.py
│ ├── asgi.py
│ └── wsgi.py
└── core/
├── admin.py
├── apps.py
├── models.py
├── serializers.py
├── views.py
├── urls.py
├── tests.py
└── migrations/
Define as entidades principais:
- User: herda de
AbstractUsere inclui o campois_librarian. - Book: representa um livro, com campos como
title,author,published_year. - Library: representa a biblioteca de um usuário e relaciona-se com livros e dono.
Transforma os modelos Python em JSON (e vice-versa):
UserSerializerBookSerializerLibrarySerializer
Usa ModelViewSet para CRUD automático:
UserViewSetBookViewSetLibraryViewSet
Com permissões e ações customizadas.
Registra os roteadores DRF:
router.register(r'users', UserViewSet)
router.register(r'books', BookViewSet)
router.register(r'libraries', LibraryViewSet)Configura os modelos no painel administrativo, incluindo exibição do campo is_librarian.
Contém testes unitários e de integração para validar comportamento dos modelos e endpoints.
- Use HTTPS em produção.
- Utilize tokens JWT para autenticação segura.
- Versione migrações e mantenha testes automatizados.
- Documente endpoints com
drf-spectacular. - Mantenha
.enve.venvfora do controle de versão.
# Ambiente virtual
.venv/
# Cache e arquivos temporários
__pycache__/
*.pyc
*.pyo
*.pyd
# Banco de dados local
db.sqlite3
# Configurações locais
.env
# Arquivos de logs
*.log
# Diretório de migrações compiladas
**/migrations/__pycache__/Autor: Abraão Brandão Curso: Engenharia de Software