Skip to content

Latest commit

 

History

History
197 lines (133 loc) · 2.83 KB

notes.md

File metadata and controls

197 lines (133 loc) · 2.83 KB

Some draft notes

While doing the project I was taking notes about many steeps. Here are some of them.

django-extensions for generate graph_models

pip install django-extensions==3.2.3
pip install pydot==3.0.2
python manage.py graph_models -a -o mini_twitter_models.png

coverage

pip install coverage==7.6.4
coverage run --source='.' manage.py test
coverage report
coverage html
coverage xml

Refs.:

Code formating and checking with black

pip install black==24.10.0
black --check .
black .

swagger

Choosen the drf-spectacular library.

REST_FRAMEWORK = {
    ...
    'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
    ...
}

About JWT

djangorestframework_simplejwt

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:

Videos:

Only docker usage notes

If using only docker:

docker build . --tag minitwitter:0.0.1
docker run -it --publish=8000:8000 --rm minitwitter:0.0.1

Bootstrapping django rest project

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 $?