Posts

Showing posts with the label django

send html mail with attachment in django

 SourceURL:file:///home/wadmin/My Files/sedn html email with attachment.docx send html page rendered mail with attachment.     views.py from django.shortcuts import render   from django.http import HttpResponse from django.core.mail import send_mail   from django.core.mail import send_mail, EmailMessage from django.template.loader import render_to_string from django.contrib.staticfiles import finders   def mailView(request):     try:         subject = 'This is a test mail'         message = render_to_string('mailfile.html')         from_email = 'arnab.gupta@weavers-web.com'         to_email = ['iamshimantadas123@yopmail.com']           email = EmailMessage(subject, message, from_email, to_email)       ...

send mail - sendgrid - django

 SourceURL:file:///home/wadmin/My Files/send mail sendgrid.docx support docs: https://github.com/sklarsa/django-sendgrid-v5     views.py from django.shortcuts import render   from rest_framework.views import APIView from rest_framework.response import Response from rest_framework import status   from .serializers import * from django.core.mail import send_mail   class MailSendList(APIView):     def post(self, request, format=None):         data = request.data         subject = data.get("subject")         message = data.get("mailbody")         mail_from = data.get("mailfrom")         mail_to = data.get("mailto")           try:             ...

viewset CRUD in django

CRUD with viewset   Views.py from django.shortcuts import render from rest_framework.viewsets import ModelViewSet from core.models import User from .serializers import * from rest_framework.response import Response from rest_framework.permissions import IsAuthenticated from rest_framework_simplejwt.authentication import JWTAuthentication from .permissions import *   class AccountView(ModelViewSet):     queryset = User.objects.all()     serializer_class = AccountSerializer     permission_classes = [IsAuthenticated, isManager]     authentication_classes = [JWTAuthentication]     # Allow only GET, PUT and POST methods     http_method_names = ["GET","PUT","POST"]   Urls.py from .views import * from rest_framework.routers import SimpleRouter   router = SimpleRouter() router.register("",AccountView) urlpatterns = [] urlpatterns = urlpatterns + router.urls...

setup .env file in your django app

 SourceURL:file:///home/wadmin/My Files/env setup django .docx How to set .env file in django project     Step 1: create a .env file in your django app. Ans paste your key credentials : key and values without using double quotes AWS_ACCESS_KEY_ID = AKIAZYB AWS_SECRET_ACCESS_KEY = A4ObpZ1HaoR5 AWS_STORAGE_BUCKET_NAME = testbucket AWS_S3_SIGNATURE_NAME = s3v1 AWS_S3_REGION_NAME = ap-south-2 AWS_S3_FILE_OVERWRITE = False AWS_DEFAULT_ACL =  None AWS_S3_VERITY = True DEFAULT_FILE_STORAGE = storages.backends.s3boto3.S3Boto3Storage   Step 2 : import os module in your mainproject ’s ‘settings.py’ and set your env variables according to it. For access .evn variables use: os.environ.get(“key_name”) AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY_ID") AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY") AWS_STORAGE_BUCKET_NAME = os.environ.get("AWS_STORAGE_BUCKET_NAME") AWS_S3_SIGNATURE_NAME = os.environ.get("AWS_S3_SIGNATURE_NAME") AWS_S3_REG...

basic CRUD with serializers + model in django

  Serializers.py from rest_framework import serializers   from django.contrib.auth.hashers import make_password   from core.models import Member   class UserSerializer(serializers.ModelSerializer):     class Meta:         model = Member         fields = "__all__"       def create(self, validated_data):         password = validated_data.get('password')         member = Member(             name = validated_data.get('name'),             email = validated_data.get('email'),             password = make_password(password),             a...