Lanka Developers Community

    Lanka Developers

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Shop

    Django Series part 01 සිංහලෙන්

    Web Development
    web development django python
    8
    9
    2141
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • isuru mahesh perera
      isuru mahesh perera last edited by

      What is Django ?

      django කියන්නේ python language එක base කරන් හදපු framework එකක්.

      then What is framework ?

      application එකක් build කරන්න ඕන කරන tools වල එකතුවක් කිසියම් standard එකක් එක්ක. එකියන්නේ authentication & authorization , form validation, database mapping, security වගේ තව ගොඩක් දේවල් වල එකතුවක්.
      තව framework එකක ඒගොල්ලොන්ට අදාලව වෙනම rules තියනව... අපිට එතොකොට e rules follow කරන්න සිද්දවෙනවා

      හරි එහනම්, Django පටන් ගන්න කලින් මේ post එකෙන් python basics ටික cover කරන්නම්.. එතොකොට එක python වලට aluth එක්කෙනේක්ටත් උදව්වක් වෙයි...

      Python Introduction

      Python is one of the high-level, support multiple programming paradigms, interpreted and general-purpose programming language that is easy to use.

      python කියන්නේ general purpose language එකක් නිසා ඔයාට ගොඩක් දේවල් වලට use karanna puluwan .

      • Web Development
      • Machine learning
      • Data Science
      • Robotics
      • Scripting

      මම දකින විදිහට python කියන්නේ දැනට තියන ලස්සනම, එවගෙම් ගොඩක් strong, programming language එකක් :wink:

      හරි එහෙනම් මුලින්ම python install karaganna download

      Variables
      data store කරන්න පුළුවන් Tempory memory allocation unit ekak

      # string
      name = "john"
      
      # numbers
      age = 22
      
      # boolean
      hasError = True 
      
      # in python world everything is an object
      type(name) 
      <class 'str'>
      
      

      Control Flow
      කිසියම් condition එකක් මත අපේ program එක run වෙන්න ඕනෙනම් අපි if / else use කරනවා

      python වල code block වල (loop , ifelse , function ) scope eka (සරලව කිවොත් area එක) අපි define කරන්නේ indentation walin.
      අපි indentation වලට spaces 4ක් use කරනවා...

      # single condition
      
      condition = True
      
      if condition:
         print('condition is true this will execute')
      
      else:
        print('condition is false this will execute')
      
      # multiple condition
      if condition:
        pass
      elif condition:
        pass
      else:
        pass
      
      

      Ternary Operator
      මේ operatior එකෙන් condition statement single line ලියන්න පුළුවන්
      [If True] if [Expression] Else [If False]

      name = "john"
      hasJohn = True if name == "john" else False
      

      Collections
      LIST,
      multiple values store කරන්න පුළුවන් data structure(layout ) එකක්
      mutable (update-able) - එකියන්නේ list එකේ store කරපු values change කරන්න පුළුවන්

      alt text

      # js wala array ekak wage
      # list eka index eka patan ganne 0 walin
      
      names = ['john', 'max', 'kevin']
      
      names[0]
      # john
      
      names[1] = "ann"
      
      names
      # ["john", "ann", "kevin"]
      
      

      Tuple
      constant list එකක් එකියන්නේ change karanna bari list එකක් ()

      names = ('john', 'kevin')
      names[1] = "max"
      
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: 'tuple' object does not support item assignment
      
      

      Dictionaries

      key value pair එකක්...
      mutable datastructure ekak
      js වල object එකක් වගේ. php වලනම් assosiative array එකක් වගේ

      person = {
         'name': 'max',
         'age': 23
      }
      
      person['name']
      # max
      
      

      Loop
      අපිට මොකක් හරි task එකක් repeatedly කරන්න ඕනනම් අපි loop use කරනවා..
      condition eka false wenakan loop eke body eka execute wenawa..
      loop එකක structure එක තමා පල්ලහ දාල තියෙන්නේ

      alt text

      # while loop
      
      number = 1
      
      while number < 6:
        
        print(number)
        number += 1         # 1, 2, 3, 4, 5
      
      # for loop
      
      numbers = [10, 20, 30, 40]
      
      for n in numbers:
        print(n)            # 10, 20, 30, 40
      
      # single line
      
      person = {
         'name': 'max',
         'age': 23
      }
      
      # items() method used to return list with all keys and values
      # [ ['name', 23], ['age', 23] ]
      
      for key, value in person.items():
         print(key)        # name , age
         print(value)      # max , 23
      
      

      Functions

      A function is a block of code which only runs when it is called.

      input - pass data (arguments)
      process - function body
      output - return data from the function

      alt text

      
      # python wala function ekak define karanna 'def' keyword eken
                     
      def sum(num1, num2):
             
        result = num1 + num2
        return result 
      
       sum(10, 20)   # 30
      
      python keyword arguments support
      sum kiyana function eka mehema call karanna puluwan
      sum( num1= 10, num2=20)
      
      python *args & **kwargs (js wala rest operator eka wage)
      
      *args  operator - function eka call karaddi pass karana arguments array ekakata convert karanna puluwan
      
      def sum(*args):
         print(args) # [10, 20, 30]
      
      sum(10, 20, 30)
      
      **kwargs operator - function eka call karaddi pass karana keyword arguments dicitonary ekakata convert karanna puluwan
      
      def sum(**kwargs):
         print(kwargs) #  { 'first': 10, 'second': 20}
      
      sum(first=10, second=20)
      
      

      scope

      සරලව බැලුවොත් scope එක කියන්නේ variable access කරන්න පුළුවන් area එක
      Python follow කරන්නේ LEGB RULE එක

      • Local(L) - Defined inside function/class
      • Enclosed(E) - Defined inside enclosing functions(Nested function concept)
      • Global(G) - Defined at the uppermost level
      • Built-in(B) - Reserved names in Python builtin modules

      local -> enclosed -> global -> builtin

      alt text

      # local
      
      name = "john"
      
      def sayName():
      
          name = "kevin"
          print(name)
      
      sayName()
      
      # methandi print wenne kevin kiyana local varibale eka... global varibale eka access karanna onanm "global" keyword eka use karanna wenawa (php wage)
      
      # global
      
      name = "kevin"
      
      def sayName():
      
          global name
          print(name)
      
      sayName()   # kevin kiyana global variable eka
      
      # enclosed
      
      name = "global name"
      
      def sayName():
          
          name = "outer name"
          print(name)   # global name eka access karanna onam variable eka issarahin **global**  keyword eka use karanna
      
          def innerName():
              
             name = "inner name"
             print(name)     # outer name eka access karanna onam variable eka issarahin **nonlocal** kiyana keyword eka use karanna ona
      
         innerName()
      
      sayName()
      
      # Built-in Scope 
      from math import floor 
      
      # floor = 'global pi variable' 
      
      def outer(): 
           
           # floor= 'outer floor' 
      	
           def inner(): 
      	# floor = 'inner floor variable' 
      	print(floor) 
      
           inner() 
      
      outer() 
      
      **LEGB RULE**
      1) floor eka inner function scope eke define karalada balanawa , thiynawanm eka gannawa
      2) nathnm outerscope eke define karalada balanawa, thiynwanm eka gannawa
      3) nathnm global eke define karalada balanawa, thiyanwanm eka gannawa
      4) nathnm built-in scope eke balanawa, nathnm error ekak throw karanwa "floor is not defined" 
      
      

      Guys meka simple overview එකක් විතරයි. ඔයා තව ගොඩක් දේවල් ඉගෙන ගන්න වෙනවා. මේ basics ටික තමා අපි django වල ගොඩක් වෙලාවට use කරන්නේ.python වල oop part එක මං දැම්මේ නැහැ මට අද time nathi නිසා. කට්ටිය කැමතිනම් කියන්න මං මේක ඉස්සරහට continue කරන්නම්

      1 Reply Last reply Reply Quote 3
      • dev_lak
        dev_lak last edited by

        niyama wadak machn... wade continue krnna

        1 Reply Last reply Reply Quote 1
        • Nubelle
          Nubelle Web Development last edited by

          meka patta mchan @waex97 supiri

          1 Reply Last reply Reply Quote 1
          • root
            root Linux Help last edited by

            superb bro. 2nd part ekath one ikmanata

            1 Reply Last reply Reply Quote 1
            • imadusanka
              imadusanka last edited by

              thanks bro. Keep it up

              1 Reply Last reply Reply Quote 1
              • MrCentimetre
                MrCentimetre last edited by

                @waex97 හැමෝටම තේරෙන විදියට පට්ටෙම ලියලා තියෙනවා.නියමයි :*

                1 Reply Last reply Reply Quote 1
                • root
                  root Linux Help last edited by

                  2nd part eka one

                  1 Reply Last reply Reply Quote 0
                  • Kalana
                    Kalana last edited by

                    niyamai wade digatama karan yanna

                    1 Reply Last reply Reply Quote 0
                    • Lakshan dhanuka
                      Lakshan dhanuka last edited by

                      hoda wadak bro digatama karanna

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      • First post
                        Last post

                      0
                      Online

                      3.7k
                      Users

                      1.3k
                      Topics

                      5.3k
                      Posts

                      • Privacy
                      • Terms & Conditions
                      • Donate

                      © Copyrights and All right reserved Lanka Developers Community

                      Powered by Axis Technologies (PVT) Ltd

                      Made with in Sri Lanka

                      | |