-
Run environment
-
pip install Django
-
pip install djangorestframework
-
pip install markdown # Markdown support for the browsable API.
-
pip install django-filter # Filtering support
-
pip install django-cors-headers # security headers
-
pip install djoser # endpoint api
-
pip install pillow # image processing
-
pip install stripe # payment gateway - options: stripe, paypal, braintree
-
Add to INSTALLED_APPS in setting.py
'rest_framework', 'rest_framework.authtoken', 'corsheaders', 'djoser'
-
Add to AUTH_USER_MODEL in settings.py
AUTH_USER_MODEL = 'djoser.User' CORS_ALLOWED_ORIGINS = ['http://localhost:8080']
-
Add middleware to MIDDLEWARE in settings.py
'corsheaders.middleware.CorsMiddleware',
-
Import include in urls.py file
from django.conf.urls import url, include
-
Add to url in urls.py file
path('api/v1/', include('djoser.urls')), path('api/v1/', include('djoser.urls.authtoken')),
-
Make migration
python manage.py makemigrations python manage.py migrate
-
Create admin user
python manage.py createsuperuser
-
Run server
python manage.py runserver
- npm install -g @vue/cli
- vue create project-name
? Please pick a preset: Manually select features ? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors ? Choose a version of Vue.js that you want to start the project with 3.x ? Use history mode for router? (Requires proper server setup for index fallback in production) Yes ? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with dart-sass) ? Where do you prefer placing config for Babel, ESLint, etc.? In dedicated config files ? Save this as a preset for future projects? No
- cd project-name
- npm install axios
- npm install bulma
- npm install bulma-toast
- npm run serve
python manage.py startapp product
Create model category Register app product to settings.py in INSTALLED_APPS
INSTALLED_APPS = [
...
'product',
]
Make migration
python manage.py makemigrations
python manage.py migrate
Import io,PIL,File in models.py
from io import BytesIO
from PIL import Image
from django.core.files import File
Register model in admin.py
from product.models import Category, Product
admin.site.register(Category)
admin.site.register(Product)
Add media url to settings.py
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'
Edit urls.py
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Create serializer.py in product app
from rest_framework import serializers
from .models import Category, Product
class CategorySerializer(serializers.ModelSerializer):
class Meta:
model = Category
fields = ('id', 'name')
class ProductSerializer(serializers.ModelSerializer):
class Meta:
model = Product
fields = ('id', 'name', 'get_absolute_url', 'description', 'price', 'get_image', 'get_thumbnail')
Import serializers, APIView, response to views.py
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import Product
from .serializers import CategorySerializer, ProductSerializer
Make view for Latest Products List
class LatestProductsList(APIView):
def get(self, request):
products = Product.objects.all()[:4]
serializer = ProductSerializer(products, many=True)
return Response(serializer.data)
Create urls.py file
from django.urls import path, include
from product import views
urlpatterns = [
path('latest-products/', views.LatestProductsList.as_view()),
]
Add path to urls.py in admin
urlpatterns += [
path('api/v1/', include('product.urls')),
]