This is the backend service for an e-commerce website, built with Django. It provides APIs for managing products, categories, regions, carts, and stock.
- Installation
- Running Locally
- Setting Up PostgreSQL on Render
- Deploying on Render
- Creating Superuser and accesing Django Admin
-
Clone the repository:
git clone https://github.com/yourusername/WSAbackend.git cd WSAbackend -
Create a virtual environment and activate it:
python -m venv env cd env/Scripts activate cd ../..
-
Install the required dependencies:
pip install -r requirements.txt
-
Navigate to the project directory:
cd WSAbackend -
Apply the migrations:
python manage.py makemigrations python manage.py migrate
-
Run the development server:
python manage.py runserver
The application will be available at
http://127.0.0.1:8000.
-
Create a PostgreSQL Database on Render:
- Go to your Render dashboard.
- Click on
Newand selectDatabase. - Choose
PostgreSQLand configure the database (name, region, etc.). - Once created, note the database URL provided by Render.
-
Update Django Settings:
- In your
settings.pyfile, in the WSAbackend directory update theDATABASESsetting to use the PostgreSQL database URL. Replaceyour_database_urlwith the URL from Render:
import os import dj_database_url DATABASES = { 'default': dj_database_url.parse('your_database_url') }
- In your
-
Apply Migrations Before Deployment:
- Ensure you apply migrations to your PostgreSQL database before deployment:
python manage.py makemigrations python manage.py migrate
To deploy the application on Render, follow these steps:
-
Create a New Web Service on Render:
- Go to your Render dashboard.
- Click on
Newand selectWeb Service. - Connect your GitHub or GitLab account and select the repository for the project.
-
Configure the Web Service:
- Environment: Select
Python 3. - src:
cd WSAbackend- Build Command: Set this to
pip install -r requirements.txt && python manage.py collectstatic --noinput && python manage.py migrate. (There touch this part on render. Leave it as it is) - Start Command: Set this to
gunicorn WSAbackend.wsgi:application.
- Environment: Select
-
Deploy the Web Service:
- Click
Create Web Serviceto deploy your application. - Render will build and deploy your application. Once the deployment is complete, your application will be available at the URL provided by Render.
- Click
To view the database follow the following commands
- Create Superuser:
- run
python manage.py createsuper
- After following the prompts and creating the user, visit
http://hosted_url/admin.com. - Fill in the credentials used previously
- run