/djangoapi

Primary LanguagePython

This Django API is designed to handle store products. It is built using the Django web framework

DEMO 1 alt text DEMO 2 alt text DEMO 3 alt text

To get started, make sure you have Python and Django installed on your machine. Then, clone this repository and navigate to the project directory in your terminal.

Learning objectives Creating a serializer Working with API views Filtering back ends Enabling pagination Executing CRUD operations Managing serializer fields Testing API views

When using python, it is recommended to use the virtual environment so that you can be able to know what versions of Python you are using.

Here is how you can create a virtual environment on mac or Windows (assuming you have Python installed and version is > 3)

1. run this command below to create a virtual environment:

(venvs will be your virtual environment name )

    python -m venv venvs

if it doesn't work, try running the following command:

 pip install virtualenv

then run to creat your virtual enveroment

 virtualenv venvs

To activate the virtual environment, run the following command:

(on Mac OS or Linux)

source venvs/bin/activate

On windows, the virtual environment can be activated by running:

source venvs/Script/activate
If you have successfully created the virtual environment, well done.

Run the following command to install the required packages:

    pip install -r requirements.txt

Now that you have, install the required packages, generate django secret key:

python 
from django.core.management.utils import get_random_secret_key  
get_random_secret_key() 

add to env file:

DJANGO_SECRET_KEY="django-insecure-YOUR_SECRET_KEY"

LET US CREAT THE ADMIN USER

Create admin user, you will be asked a name and Password

  • Name: mwamuziscodev
  • Password: mwamuziscode@

(you can of course use any name and password you want) example:

Create admin user:

    python manage.py createsuperuser
python manage.py createsuperuser
Username (leave blank to use 'admin'):
Email address: admin@gmail.com
Password:
Password (again):
Superuser created successfully.

Finally run the server with the following command:

python manage.py runserver
  • if you want to specify the port number, you can use the following
python manage.py runserver 8000

if you want to specify the IP ADRESS, you can use the following

python manage.py runserver 127.0.0.1:8000

Well done. Now go to the url below and explore the API

This is a sample webiste showing product being added You should now be able to access the API at http://localhost:8000/

VIEW ALL PRODUCT ON THE HOMEPAGE

http://127.0.0.1:8000

VIEW ALL PRODUCT IN JSON FORMAT IN THE DJANGO-RESTFRAMEWORK API

http://127.0.0.1:8000/api/v1/products/

GET ONE PRODUCT, HERE YOU CAN RUD (retrieve, update, delete)

http://127.0.0.1:8000/api/v1/products/1/

PICTURE CAN BE UPLOADED FROM PRODUCT FILE