These are all backend modules for the OVRAT project structure
Sure, here's a markdown file for installing and configuring a Django Rest Framework project with SimpleJWT authentication using mkvirtualenv:
- Python 3 installed on your machine
- pip package manager installed on your machine
- virtualenvwrapper installed on your machine
- Install virtualenvwrapper:
pip install virtualenvwrapper
- Add the following lines to your
~/.bashrc
or~/.zshrc
file:
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
- Create a new virtual environment:
mkvirtualenv myprojectenv
- Activate the virtual environment:
workon myprojectenv
- Install Django and Django Rest Framework:
pip install django
pip install djangorestframework
- Install SimpleJWT:
pip install djangorestframework-simplejwt
- Create a new Django project:
django-admin startproject myproject
- Create a new Django app:
cd myproject
python manage.py startapp myapp
- Add
'rest_framework'
and'rest_framework_simplejwt'
to theINSTALLED_APPS
list insettings.py
:
INSTALLED_APPS = [
# ...
'rest_framework',
'rest_framework_simplejwt',
]
- Configure SimpleJWT authentication in
settings.py
:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
}
from datetime import timedelta
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=30),
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
'ROTATE_REFRESH_TOKENS': True,
}
- Configure URL routing in
urls.py
:
from django.urls import path, include
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
urlpatterns = [
path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
# ...
]
- Create a serializer in
serializers.py
:
from rest_framework import serializers
from .models import MyModel
class MyModelSerializer(serializers.ModelSerializer):
class Meta:
model = MyModel
fields = '__all__'
- Create a view in
views.py
:
from rest_framework import generics, permissions
from .models import MyModel
from .serializers import MyModelSerializer
class MyModelList(generics.ListCreateAPIView):
queryset = MyModel.objects.all()
serializer_class = MyModelSerializer
permission_classes = [permissions.IsAuthenticated]
- Configure URL routing for the view in
urls.py
:
from django.urls import path
from .views import MyModelList
urlpatterns = [
path('mymodel/', MyModelList.as_view()),
# ...
]
- Migrate your database:
python manage.py migrate
- Run your server:
python manage.py runserver
That's it! You should now have a functioning Django Rest Framework project with SimpleJWT authentication.
Ici il s'agit de comment installer et cofiguer le projet chez soit
- clonner de repositiry
- installez python dans votre machine
- installez VIRTUELEN via la commande
pip install virtualenvwraper-win
- créez un environement vituel via la commande
mkvirtualen non_env
- ouvrez le repo avec vs code, ouvrez le terminal
- activez l'nvironnement virtuel avec la commande
workon nom_env
- Installez les dépendences via la commande
pip install -r requirements.txt
- Tapez la commande suivante pour lancer le projet
py mannage.py runserver
POST : /api/token/
Parameter | Type | Description |
---|---|---|
username |
string |
Required. |
password |
string |
Required. |
ici il s'agit de la route qui va permettre d'avoir un token d'authentification
GET, POST : update_profile/
Parameter | Type | Description |
---|---|---|
last_name |
string |
Required. |
first_name |
string |
Not required. |
email |
string |
Required. |
username |
string |
Required. |
POST : change_password/
Parameter | Type | Description |
---|---|---|
old_password |
string |
Required. |
password |
string |
Required. |
confirm_password |
string |
Required. |
POST : reset_password_get_token/
Parameter | Type | Description |
---|---|---|
email |
string |
Required. |
POST : reset_password_confirm/{uidb64}/{token}
Parameter | Type | Description |
---|---|---|
email |
string |
Required. |
Url Parameter | Type | Description |
---|---|---|
uidb64 |
userid in base64 |
Required. |
token |
string |
Required. |
GET /api/categories/
Parameter | Type | Description |
---|---|---|
id |
int |
|
name |
string |
GET /api/courses/
POST /api/courses/
Parameter | Type | Description |
---|---|---|
id |
int |
|
name |
string |
|
description |
string |
|
instructor |
User |
|
categories |
Array of gategories |
Parameter | Type | Description |
---|---|---|
name |
string |
Required |
description |
string |
Required |
instructor |
User |
Required |
categories |
Array of gategories |
Required |
GET /api/courses/{id}/
PUT /api/courses/{id}/
DELETE /api/courses/{id}/
Parameter | Type | Description |
---|---|---|
id |
int |
|
name |
string |
|
description |
string |
|
instructor |
User |
|
categories |
Array of gategories |
Parameter | Type | Description |
---|---|---|
name |
string |
|
description |
string |
|
instructor |
User |
|
categories |
Array of gategories |
GET /api/lessons/
POST /api/lessons/
Parameter | Type | Description |
---|---|---|
id |
int |
|
name |
string |
|
description |
string |
|
instructor |
User |
|
categories |
Array of gategories |
Parameter | Type | Description |
---|---|---|
name |
string |
Required |
description |
string |
Required |
instructor |
User id |
Required |
categories |
Array of gategories |
Required |
GET /api/lessons/{id}/
PUT /api/lessons/{id}/
DELETE /api/lessons/{id}/
Parameter | Type | Description |
---|---|---|
id |
int |
|
title |
string |
|
content |
string |
|
course |
Course object |
Parameter | Type | Description |
---|---|---|
title |
string |
Required |
content |
string |
Required |
course |
Course id |
Required |