Posts

Showing posts from February, 2021

django media

  settings MEDIA_URL= '/some/' MEDIA_ROOT=BASE_DIR main url from  django.contrib  import  admin from  django.urls  import  path,include from  .  import  views from  django.conf  import  settings from  django.conf.urls.static  import  static urlpatterns = [     path( '' , views.index, name = 'indexname'  ), ]+ static(settings.MEDIA_URL,  document_root =settings.MEDIA_ROOT) template   < img   src = "{{i.image.url}}"   class = "card-img-top"   alt = "..." >

def str method

  from  django.db  import  models class   Catagory ( models . Model ):     name=models.CharField( max_length = 50 , default = 'none' )      def   __str__ ( self ):          return   self .name

register a model in admin

    from  django.contrib  import  admin from  .models  import  Registry # Register your models here. @admin.register (Registry) class   RegistryAdmin ( admin . ModelAdmin ):     list_display=( 'name' , 'email' , 'password' , 'date' ) or from  django.contrib  import  admin from  .models.productmodel  import  Product  # Register your models here. class   AdminProduct ( admin . ModelAdmin ):     list_display=[ 'name' , 'price' ] admin.site.register(Product,AdminProduct)

postgres connect with django

  DATABASES = {      'default' : {          'ENGINE' :  'django.db.backends.postgresql_psycopg2' ,          'NAME' :  'DBSHOP' ,          'USER' :  'postgres' ,          'PASSWORD' :  'password' ,          'HOST' :  'localhost' ,          'PORT' :  '5432' ,     } }

free api

  https://devresourc.es/tools-and-utilities/public-apis/apixu

async, await 1

  // function mydisplay(mal){ //     console.log(mal) // } // const mypromic = new Promise(function executor(resolve,reject){ //     let x=2; //     if (x==0){ //         console.log("resole part") //         resolve("okk") //     } //     else{ //         reject() //     } // }) // mypromic.then( //     function one(value){ //         mydisplay(value); //     }).catch(function two(){ //         console.log("eror") //     }       ...

promise 2

  function   mydisplay ( mal ){      console . log ( mal ) } const   mypromic  =  new   Promise ( function   executor ( resolve , reject ){      let   x = 0 ;      if  ( x == 0 ){          resolve ( "okk" )     }      else {          reject ( "not ok" )     } }) mypromic . then (      function   one ( value ){          mydisplay ( value );     }). catch ( function   two ( err ){          mydisplay ( err );     } )

promise 1

  function   mydisplay ( mal ){      console . log ( mal ) } const   mypromic  =  new   Promise ( function   executor ( resolve , reject ){      let   x = 2 ;      if  ( x == 0 ){          resolve ( "okk" )     }      else {          reject ( "not ok" )     } }) mypromic . then (      function   one ( value ){          mydisplay ( value );     },      function   two ( err ){          mydisplay ( err );     } )

callback

console . log ( "start" ) function   execute ( email , password , callback ) {      setTimeout (()  =>  {          console . log ( "Fatching data" )           callback ({ usermail : "email" })          }, 3000 );      } execute ( 'maruf@gmail.com' , 1234 ,   function  ( userx ) {  console . log ( userx ) }) console . log ( "end" )

Common javascript regx

Image
  Top 15 Commonly Used Regex May 30, 2018 / Javascript ,  Tips & Tricks / Niket Pathak /   3   min read Regex Regular Expressions aka Regex are expressions that define a search pattern. They are widely used for validation purposes, like email validation, url validation, phone number validation and so on. Forming Regex: A regex is written between two  forward slashes  ( / ) delimiters. These delimiters are essential only for certain Regex engines (JS,PHP..). It is then followed by 2 flags: i  :  Ignore case  Flag, ignores the case(uppercase/lowercase) of the input string g  :  Global  Flag, searches for multiple matches instead of stopping at the first match 1 2 3 4 /* Regex Example */ /hello/ig /* will match the word "hello" irrespective of its case and     will return all found matches. */ A quick cheat sheet for those of you who do not remember all the rules of Regex Cheat Sheet – Regex Rules Character clas...