Title here
Summary here
To improve my understanding how the workflow of API’s works in a Fullstack app i created a small todo App.
In the root folder, on the terminal create a virtual environment.
Terminal command: python3 -m venv venv
Activate command: source venv/bin/activate
pip install django
django-cors-headers
pip install djangorestframework
django-admin startproject backend
-> cd to the backend folder
python manage.py startapp
[name of the app]
Go back to the root folder and:
npm create vite@latest frontend -- --template react
-> cd frontend
npm install
code .
-> Open two terminals and make sure your virtual environment is active
-> cd to backend
python manage.py runserver
-> cd to frontend
npm run dev
```Python
CORS_ALLOWED_ORIGINS = [
"http://127.0.0.1:5173",
"http://localhost:5173",
]
```
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
External Apps
'rest_framework',
'corsheaders',
Internal Apps
'<Appname>', -> Change to name of the Django App!
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"corsheaders.middleware.CorsMiddleware", -> Add this to Middleware!
]
And we are done whit the Main App Setup.