Posts

React Js

const simple =()=>{ return( <h1> hello</h1> ) } export default  Router in React Js npm install react-router-dom first create a router file import { Routes , Route , Navigate } from "react-router-dom" ; import Hooks from "../components/hooks" ; import Cours from '../components/carousel' import App from "../App" ; const AppRouter = () => {   return (     <>           < Routes >       < Route path = '/' element = { < App /> } />       < Route path = "/hooks" element = { < Hooks /> } />       < Route path = "/cours" element = { < Cours /> } />     </ Routes >     </>   ); }; export default AppRouter ; Wrap the it in  BrowserRouter in the main.jsx import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' import './index.css' import 'bo...

django

  # Request Method Checker for Web  for API from django . views . decorators . http import require_http_methods @ require_http_methods ([ 'POST' ]) def testFun ( request ):     name = "test"     return HttpResponse ( name )

Flutter with django back end

when taking a build in flutter you should add  <uses-permission android :name ="android.permission.INTERNET" />  this in  adoroidmanifest xml in android and then take the build   First add the http package, save the pubspec.yaml file. dependencies : flutter : sdk : flutter http : ^0.13.4 # then    flutter pub get use serializers in django and seprate views for the serializers Future< void > signup (BuildContext context) async { String username = userNAmeController . text ; String email = emailController . text ; String password = passwordController . text ; String rePassword = re_passwordController . text ; // Validate input if (username. isEmpty || email. isEmpty || password. isEmpty || rePassword. isEmpty ) { ScaffoldMessenger. of (context).showSnackBar( SnackBar (content: Text ( "Please fill in all fields" )), ); return ; } if (password != rePassword) { ScaffoldMessenger. of (context).sho...

cros headers and csrf 403 forbidden errror solution

    install core headers and add it in installed apps SESSION_ENGINE = 'django.contrib.sessions.backends.file' SESSION_FILE_PATH = os.path.join(BASE_DIR,'sessions') SESSION_COOKIE_AGE = 86400       SESSION_EXPIRE_AT_BROWSER_CLOSE = False CORS_ORIGIN_ALLOW_ALL = True CORS_ALLOW_HEADERS = ['*'] CSRF_COOKIE_SAMESITE = 'Lax'  # Or 'Strict', depending on your setup CSRF_COOKIE_SECURE = False

Custom Middleware in django using session key

 from django.shortcuts import render,redirect class SessionAuthenticationMiddleware:     def __init__(self, get_response):         self.get_response = get_response     def __call__(self, request):         print(f"Request path: {request.path}, Session key: {request.session.get('session_key')}")         print("Middleware executed")  # Debugging line         session_key = request.session.get('session_key')         if not session_key:             print("Session key missing, redirecting...")  # Debugging line             # Allow access to the login page (which is at '/') and the signup page (which is at '/signup')          ...

python mail sent using thread

mail sent from django.core.mail import EmailMessage from django.template.loader import render_to_string from threading import Thread def send_email_threaded(otp, recipient_email):     """Helper function to send email asynchronously in a separate thread."""     try:         # Render the HTML template with the OTP         html_content = render_to_string(             'otp_email_template.html', {'otp': otp}         )         # Create the email object         email = EmailMessage(             subject="Your OTP for Login",  # Email subject             body=html_content,  # HTML content for the email    ...