While doing the project I was taking notes about many steeps. Here are some of them.
pip install django-extensions==3.2.3
pip install pydot==3.0.2
python manage.py graph_models -a -o mini_twitter_models.png
pip install coverage==7.6.4
coverage run --source='.' manage.py test
coverage report
coverage html
coverage xml
Refs.:
pip install black==24.10.0
black --check .
black .
Choosen the drf-spectacular
library.
REST_FRAMEWORK = {
...
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
...
}
WIP: when other parts are finished came back to this.
Add the library to requirements.txt:
dj-rest-auth==6.0.0
Add this to settings.py:
INSTALLED_APPS = [
...
'rest_framework.authtoken',
'dj_rest_auth',
...
]
from dj_rest_auth.views import LoginView
path('login', LoginView.as_view(), name='login'),
python manage.py startapp userauth
REST_AUTH = {
'USE_JWT': True,
'JWT_AUTH_COOKIE': 'jwt-auth-c00kie',
'JWT_AUTH_REFRESH_COOKIE': 'jwt-auth-refresh-c00kie',
}
docker-compose exec apidrf python manage.py createsuperuser
Example:
myadmin
[email protected]
dd4095ea391a
dd4095ea391a
docker-compose exec apidrf python manage.py makemigrations
Access
When searching for JWT found that there are more than one library:
- https://github.com/iMerica/dj-rest-auth sucessor of django-rest-auth
- https://github.com/Tivix/django-rest-auth deprecated in favor of dj-rest-auth
- https://github.com/jazzband/djangorestframework-simplejwt seens updated
Videos:
If using only docker:
docker build . --tag minitwitter:0.0.1
docker run -it --publish=8000:8000 --rm minitwitter:0.0.1
python3 -m venv .venv \
&& source .venv/bin/activate \
&& pip install --upgrade pip==24.2
pip \
install \
djangorestframework==3.15.2
pip3 freeze > requirements.txt
pip3 install --requirement requirements.txt
django-admin startproject minitwitter .
python manage.py migrate
python manage.py runserver
curl http://127.0.0.1:8000/ | grep -q 'The install worked successfully! Congratulations!'
echo $?