0% found this document useful (0 votes)
12 views9 pages

IT Chap 10

The document discusses the View-Controller Architecture of Ruby on Rails and compares it with Django, highlighting the features and advantages of both web frameworks. It explains Django's 'batteries included' philosophy, which provides pre-built features for rapid web development, and outlines the steps to create a sample Django application. Additionally, it covers the advantages and disadvantages of using Django and Ruby on Rails for web application development.

Uploaded by

tanzeemfathimazr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
12 views9 pages

IT Chap 10

The document discusses the View-Controller Architecture of Ruby on Rails and compares it with Django, highlighting the features and advantages of both web frameworks. It explains Django's 'batteries included' philosophy, which provides pre-built features for rapid web development, and outlines the steps to create a sample Django application. Additionally, it covers the advantages and disadvantages of using Django and Ruby on Rails for web application development.

Uploaded by

tanzeemfathimazr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 9
-View-Controller Architecture of Ruby on Rails of Ruby on Rails Required to Work with Ruby on Rails {Sample Application in Ruby on Rails ges and Disadvantages of Ruby on Rails SSG 88 58 0 o# Ty” ° ™ttb_bl'#"ith€bpe» ZG RRO SSS meworks designed to uDPER thd dor ey iceton rameworks ae sofware f eh He a olcatons and webservices Tey provide a standard way to erat 3 scons eficenty This means that developers don't have renee onan edhe) can oasson bulge et deploy web applications the wheel everytime they build a new web application features of the Web application frameworks typically include libraries, APIs, and tools that help deve : gration, user authentication, and session handle common tasks such as database integra : managemer smeworks are an essential tool for modern web development, and are used fy, word to build everything from simple websites to complex web application: web application developers around the and services ‘some popular web application frameworks include Django, Ruby on Ralls, Flask, and Express, Let us discuss Django and Ruby on Rails inthis chapter. ie =— 10.2. Django Django isa high-level web framework that is written in Python. Django provides a set of libraries, APls, and tools for building web applications quickly, easily and efficiently. Django's primary goal is to simplify the process of web development by providing well-organized and structured framework. Django is known for its elegant design its powerful features, and its large and active community. Django isa powerful and flexible web framework that is well-suited for building a wide range of web applications from simple blogs to complex socal networks and e-commerce platforms. Django has a philosophy of "batteries included’. It means Django comes with pre-built features, This philosophy comes from Python. The pre-built features are in Django's contrib packages. They lopment tasks. Some of the pre-built features are: offer solutions for common but complex web de + Theadmin package provides an administration interface. Ichelps in managing the application's data + The auth package has a complete user authentication system. + The cotenttypes package helps in creating dynamic models. It allows Django apps to work with other applications’ models. + The flatpages package helps create simple HTML content pages. These pages do not need a ‘model to manage their data. + The gs package isa geographic web framework It helps build geospatial web applications. + The humanize package provides Django template filters. These fiers help in adding a"humad) touch” to data tn simple terms, Django is ike a toolbox. Iti led with ready-to-use web development tools These tools help developers build robust web applications efficiently, Developers can focus more of Aapplication-specific tasks. They do not have to worry about common infrastructure issues, He means an Dans comes ih peat yam aes MT no process of web devlopmenthyprndags a ° ives 1 philosophy of "batteries included” mene pr med an strucrared jpeg ee rc Poe ve Model View-Template (MT) architectural pater, wih sa vrton oe ser (MVC) pattern. The MVT pattern separates the apltion ge ne aneponents: models, views, and templates, | Django Rls (urlspy) HTTP Request ae Forward Request Appropriate View ITP cesponse awe View Read/Write [Model (views.py) Data aur ‘Template html of Django. figure 10.1 :'The MVT architecture) . a ey aieences. nthe MVT pater nthe M¥T pater is similar to the MVC pattern but with SOmeG} © et pers an focusom ‘tntoler logic is handled by the Django framework a can ant | and templates, This makes it easier to build web APP "ig about the details of the controller logic scien cid 4: Models: Models are used to define the data acu f Moiese Pion cas ‘lated to the data access, validation, behaviors. © vou ry eo that define data structure and provide mechanism database = = =< a In addition to this, Django uses a URL mapper to redirect HTTP requests to the rig the URL. This function. {In Django, the process starts when a web application waits for HTTP requests from a wel receiving a request, the application determines what is needed based on the URL and (or GET data. It might read or write information fr request. The application then returns 2 response to the web browser, often dynami HTML page by inserting the retr te sthedatanstlet mplates, neta MDhango, Templates: This the presentation layer. It involves the decisions related to the Implemented sing HTML, SS, and JvaSenpt. Templates define the stucrre gyal of the response, and can include placeholders for dynamic content. A view can rt out treate an HTML page using a template, populating it with data from a model ical a iy define the structure of ny typeof file, not jast HTML, template ca tht View based on © a8 data toa view, apper can also match certain patterns in the URL and pass these b browser Op Possibly Post KS to satisty the cally creating an database or perform other tas red data into placeholders in an HTML template, 10.2.2 Features of Django Django high-level Python web framework that provides a wide rang Aevelopers build web applications quickly and effcienty. ie Of features and toolsto help [Llp tm i ] Some ofthe key features of Django include 1, Object-Relational Ma developers to define provi code pping (ORM) Support: Django provides a powerful ORM system that allows the data structure of the a 4 high-level abstraction upon a relational database th ot : eee of SQL to create, read, update, and delete data and, ‘schemas in a database, : the appleaion without having to write any code, The administration 3, Authentication Framework: Djan; n hiedeaey ea a \ ace i ig0 Provides a builtin authentication framework that makes it i authorization tothe application, The authentication framework gin, logout, password reset, and more, ve ching ame ‘vesults of expensive eee Speratons sche datbare rcs Ateperiormancsftbeampleatan, atte ees oF that allows developers to cache the API cals. This can sinicaty impo ain Sapper 43 ee bl ape qi iaioN system, Tis makes it easy to erate web ap ee he world: sho ngs Dango provides a powerfl URL routing sat usa any to reste clean and uersenly ORs te appege ve ge System: Django provides a powerfl tempat sytem ht ei lao na comes with a lightweight web server that makes it easy to develop eatin lal uaa paiein support for AJAX, RSS, and “Other Frameworks: Dango provides bul psssanl ather Frameworks, making iteasy to add advanced functionality to the portable itn support or AJAX application, jango is written in Python, whlch sa portable programming language tat rns on mary Migrms induding Lino Mae OSX and Windows. This makes en todo an ely Dango appl 1 maotainable Django is designed tobe malnanable and rearbe The code is writen sing design 4 Tndples and patterns that encourage the ceaton of maintainable and reusable code. For example, Dango makes use of the "dont repeat yoursl” (DRY principle to aod unnecessary duplication of ode This makes It easier to maintain and update the application overtime, and reduces the risk of introducing bugs or errors reations on a wide range of systems. Ta Software Required to Work with Django rung with Django necessitates the installation of some specifi software. These are detailed below: 1. Python: Django is entirely written in Python, a general-purpose, interpreted, interactive, object oriented, high-level prograruming language. To us the latest version of Django Python 265 or a more recent version is necessary Python is compatible with numerous platforms, including Linux and Mac OS X. Download and install the latest version of Python from the official Python web site (www.python.org). Django Django adopt the "bates ined” approach nd provi nos oy developer might need, directly ou of the box, Core Django design principles encompass loose coupling, eae the "Don't Repeat Yourself” (DRY) principle, fast emrees = clean design. The latest version of Django can be downloaded from soon x6 nc download (or) we can install Django using the| ‘below command in command prompt Pip install Django==4.2.3 Beco Database System: Django supports both QL and NoSQL databases, The Include PostgreSQl MySQL, SQLite, Oracle, MongoDB, and Google APPENBEPAES Web Server: Django comes bundled Wit a ncaa at testing of applications, This server sateady cong re for other restarts whenever there is @ moalfietion in the code: Popular web servers like Apache and ightPa multingual we sites through its cations that canbe used by people at allows developers to map URLs to allows develo 1 Tem on layer ofthe aplication using HTML, C35 and avserpe. me } | } } } a 10.2.4 Creating a Sample Application in Django = Let's create a Django application that will display the message “Hello, BCA students, Django". The detailes steps are shown below. Sent. Wel to Step1: Create a New Django Project: This process involves makin, new dre pret les wil be stored For instance the project name could be mee MAE the Django project can be created with the following command: elcome’, The BEE Command Prompt \>django-aduin startproject BCANelcome Ban fl The install worked successfully! Congratulations! ‘You ate seeing this page because DEBUG in your ‘setings fle and you have not configaed any Ute ted into the new project Step 2: command prompt. The command prompt needs to be navigat directory (BCAWelcome), and then the following command is 1 3: Create a Django Application: A new application witin the project can be created using the startapp command, Let's name this application "BCAApp”. The following command, ‘when run inside the BCAWelcome directory, creates the new application: 1 Si Commun Promg-pynon manage amscwer \Bciielcone>python manage.py runserver latching for file changes with Staticloader erforming system checks 1 Command Prompt = \BCAMeLcome>python manage.py startapp 8CAAOP =BcAApp that contains files for managing, Bration(s). Your project may not work properly ‘This command creates anew directory named "BCAAPP. erations for app(s): adain, auth, contenttypes, python mana {he application about the new 2 To tell the Django roect Py migrate’ to apply thes. {ip4; Update the Project's settings py FUE: TTT ED, apps ust in the stings py fle ply 12, 2023 - 17:06:10 aplication, it needs tobe adel the NST con Fd the using Settings “BAelcone. settings! Open the settings py ile located nthe BON serve at nts/327-0.0.36000/ INSTALLED_APPS ist and add BCAAPD' “ INSTALLED_APPS = [ = ajang cones 2080 agengeanteib aH nei content 708» terting. development After running this command, the deve correctly, a message statin hp: //127.0.0.1:8000/ sh vajangoncontrbs881008 2 Open a browser and enter “hit a et ser and enter “htp://127 0.0.:8000/* into the fe gt the deta jong, contrb. nee Bee un 1/3127 9.0.1:8000/" into the URL box, We get the ‘jangoecomedb, stant lopment server starts, If everything 1s Set UP thatthe server is running and listening for connedions Ot ae ‘ould be visible, e e a step 5: Step 6: ‘Add a Mapping to the Application in the urlspy File: Django deter display based on the URL. provided, This is controlled in the: in Urlspy file, a vi View: bbe created first In BCAAPp/views-py, add the following code: from djang.nttp import HtpResponse ni det welcone(request) return Hetpkespon (He, BOA st ecSwello, DOA students, Nelcone_ to bjango}} is code defines a function called "welcome that wil return the desired wegceo— ‘This code defines a funct sired message Ne i fe ceed weg ere be crated a the CAN ree a following code should be added: © lie | from aSango-urls sport path a | |e re vi | from. por urapatterns = ( PRtH("", views welcome, name-‘welcone'), | This code creates a URL route for the view just created. See ae cr ly. the projects urs py file need tobe updated to include the applications ulepy file. Open BCAWelcome/BCAWelcome/urls py and modify it as follows: from dJengo.contri Seport admin from diengo.urls import Snclude, path | urtateerns = ( | paccadnin/", adein.site.urs), Path", Ancdue(“BcAtgp.urs')), 1d tie Result: Navigate to tp localhost 00079 pinigc students. Welcome to Django’ shouldbe dna me 2 yh git running of the Django application, Indcatng the sucess, etl! 5 Pee ges and Disadvantages of Django [vantages of Dango as smponents, it enables rapid development. oa » yangolsa versal ramewort tated ise ee oem mea nent ee ee en nian ie cas 6 a er ‘ traffic websites. = — E Scripting (XSS), Cross Site Request Forgery (CRF), ait Lot 2 f support, with plenty of resources, documentation. Disadvantages of Django Run the Server: With all the above st the application in action. F following command sho -pS completed, the server can be run again to see fom the command line, inside the BCAWelcome directory, the be run: Command Prompt *\BCAliel.come>python manage.py runserver: — + leaming curve: Aithough Django bas exsent document beng for beginners “ $e duno on fered moe ne pie Wh ncn a reno abe as cient amevoncmptbehseT OMSL a ga $ lak of Cnrentans Django ene a fens 2 cm Seon abot) whem to $ Ona Limitations White Django's ORM objet Relate SIFTS gu a et ‘ays suit for complex atabas ope Sestantage of usingan ORM, 10.3.2 Features of Ruby on Rails Ruby on Rails is a powerfal and exible web application framework that provides awi build web applications quickly and effcienty, *® NRe of features and tools to help developer: 1 pases cmaratnr QQ Aacsnecore: Ras ws oe MW ors ee pa ee sre as canpeoets eich SAE ces pe ofr argu eve we sas te Gals Gee tans arp uk Nr FB: cor as poor sc ObjasPecioad papaag(ONATjae aeeee 2 sige get pteinbinate peers eee Hs tema ay perso cng pecs penerres ase | peepee etaig etalaegtes | 4 Rng ta rode ome ong tem ht ps UR te cnroers nd cena | pao Dattern, which 5 the data and 4 the contro, COM Which 4 Such ap 5. Views: Ralls provides a templating sytem called ERB (Embedded Ruby), which allows develope cemmbed Ruby code in HTML templates. a Testing Ral provides built-in testing famework that makes it easy to write and run tess forthe pplication. 7, Gems: Ralls uses RubyGems, a package manager for Ruby, to manage dependencies and add functional tothe aplication. 8. Convention Over Configuration: Ralls emphasizes convention over configuration, which means that developers can get started uiciy without having to spend aot of time configuring the application, | % Security: Rais provides a numberof security features, such as protection against crossite scripting | J. 5S cose equs forgery (CRP) tak | 20 ternationaization (18a): Rails provides built in support for internationalization, making it easy | __ tocreate applications that support multiple languages and locales ———— 10.3.3 Software Required to Work with Ruby on Ralls Working with Ruby on Rails necessitates t below: the installation of some specific software, These are detailed 4. Ruby: Ruby is the core programm ar yh cant, Programming language used in RoR. Ruby Is object-oriented and which makes Re cutemely lexible ts syntax is designed to be intuitive and easy to read nan Web dora ellen! anguage fr scripting and rapid application development in mre can download the atest version of Ruby fromthe official website at »//mwewsruby-lang.org/en/downloads,, 2 Rails: Ralls ote referred to as ‘writen in Ruby. 1's a "gem" or Controls (MVC) architecural Ruby on Ralls is a web application development framework Nbrary in the Ruby ecosystem, Rails uses the Model-VieW= pattern and emphasizes Convention over Configuration —————————— ve Ropet wourself (DRY) Prine, whieh mat pont tudes everytNg Needed to erente daibaasee jyonralls tr: While Rails comes with SQLite by defau Some 3M ste Tne Png ya ta ee ss rgly on he Teqdlements ofthe spel ra be aansse IPP WEBrick is a Ruby-based web server that ships with Ruby bu is reer for production use due tots performance characteristics Puma and eg He mend i eon for production applications and there ae many others including Passngee omsmon fo an om server used often depends on the deployment environment and the specific i eds ai ‘We need to install Git to download the required packages or libraries when we : ins) Gg Rais. We can download it from the offal Gc website: hitps:/gitsemcom/ seeinstal TFaating a Sample Application in Ruby on Rils ae cafals application that will display the message ello, BCA stdens Wecometo Ral sesjed steps are shown below. roy: Before installing Ruby on Rails, we need to Install Ruby sel This can be ‘bylnstaller for Windows. Vist the oficial Rubylnsaller page a ttps:// load the latest version. Run the installer and follow the stall any dependencies if prompted. sealed ste 1 Install Ruby: dane using the Rut rubyinstalleorg/ and down! instructions, making sure to also in nce its Installed, verify using the below command. BH Command Prompt :\Users\adain>ruby -V ee een tpn). 05-30 revision es1en4race) (ainorversl ymand prompt and (PS 2.Insall Ralls; After Ruby fs installed Ralls can be installed: Open com Inthe following command: a= ere ‘This command tllsthe gem package manager (which is incuded: ra. 3 install the Rails library. Ris! RS 10 downoag * ane 3. Create a New Rails Project: Now we can create @ new Rai - ils project. We "BcARasProjec’. To crate anew Ral project run the fllwang come tame the prompe m4 the command Command Prompt ris new BCARAIjea k prails new BCARAIIsProject ‘This will create a new directory named "BCARallSPro} ject” in current a ‘generate the basic skeleton of a Rails application. rectory, and ie wi ‘rages and Disadvantages of Ruby on Rails ‘4, Create a Controller and View: Next, we need to create a controller and. ye view The, en processes ncomingrequessandthe view s what gets displayed totheuser Nava let_ ganeeen ot Rails projec directory BCARailsProject and run the following comamans se ay on Ralls is designed to mae ey bal eb sa bevelopment Ruby on Rais is desig 257 bul eb pais dy a 2 Carat it provides a wide range of features and tol that make It esy to get tre and bl Spctons rapid et carmen et started quick without having spend alien plan ni Architecture: Rails follows the ModelView-Cnoler (YG) acl ptr we = 2 dos the application into three maln component the moll the vw ante lr Ts penne a i, re ae ne ‘eon of concerns makes it easier o maintain ad med th apt cet jew: Now we need toedicthe view to display our message. In the BCARallsProjc ‘ tonal ele tee wih so2/ews/wscome dircionythere shouldbe aflenamedindexmlerh Opetisead__ > Aéefecr:Fls proves an Oe elt am replace its contents withthe following: siento work wth canbe and a aS eee eee Hello,BCA students, Welcome to Ralls 2 Testing: als provides a ull testing fram spplaton © Update Routes: Open the le BCARalsroject/config/rowtesrb and lok or alinethat begs Tas, wigs a numberof sect fetes sch os withRalsapplication routes raw do. ere we need to tell Rais what page tm display whenwe _* Sa Nals provides annie! avigate tothe root URL of our application Add the following line Inside the draw do bloc, —_0SSanerose ste requess forgery (CSR) root welcometindex’ (i Command Pome | F \BcARaLsProjectorails generate controller Welcome index ‘This wil create anew controller named ‘Welcome’ and a view named" agit sete ri Tees [Disadvantages of Ruby 01 ‘This tells Rails to use the index action of the welcome controller as the site's root page. 7, Run the Server: Finally, we can run our application, Inthe command prompt, ensure that We stat ar Inthe BARalcroe don andre lowing ened throat urn sere ba cores Seam ae ‘equi high performance or scalability epics eer ee a | et © Scalabiity: Rats can be dificult to scale or large ae Motdabae eres orcomperbusiesS 0 yg uh S\BCARAI1sProject>rails server + Dependencies: Rails relies on a numberof third {or appcacons tat ‘omanage dependencies and updates: framers We should see output indicating mee thatthe server is running. Open a web browser and mE © Fexbiy: Rais can be less flexible tah ‘ott: //locathost:3000/. We should see the message Hello, BCA students, Wlcame Fal comples business Bacar et of cation ; = Yew e ex be Spy She . Write the a mework? jon Framework. pplication fran penefits of using Web Applicati | Whatis web 4 ication Frameworks. ny two Mention @ web Appl write ant two What is Django ? Mention any benefits of using Django. What is Ruby? What is Ruby on Rails? Mention any benefits of using Ruby on Rails. Wak scealaiae arr) What is Django ? Explain the Model-View-Template Architecture of Django. vantages and disadvantages of Django- of Ruby on Rails. Write the advantages and disadvantages ed ino SA uous Explain the features of Django. Explain the process of creating a sam| Explain the Model-View-Controller At Explain the features of Ruby on Rails. ple application using Django. rchitecture of Ruby on Rails. Explain the process of creating a sample application using Ruby on Rails. Sete

You might also like