 I am taking out this presentation with introduction to Django Has anybody heard of Django? There are quite a few, quite a few, okay, that's good So, first of all, who am I? I am Uthkarsh and I work with MOOC edX lab and I, apart from coding, I like birds and books, okay I've been making web apps since 1.5 years and since I joined this particular organization I have been pushed and asked to work with Django and Python It's been almost a couple of months ago So, the objectives for this particular presentation are overview of Django I see many of you don't know Django then those who know Django please bear with us because we'll be taking it for right from basics and I'll be covering the basics only and we'll unchain the Django, that is Django Unchanged that is that architecture, we'll study the architecture of it and just a simple project on it and the flow of the project, that's it No big deal So, what is Django? Django is a high level Python web framework that encourages rapid development and clean and pragmatic design It's, in one sentence, the complete Django has been explained One by one I'll explain that Keywords being high level Python web framework and clean and pragmatic design, rapid development One more interesting thing is Django has been used in different kind of many websites Below you can see Dropbox The second one, can you guess the logo? Pinterest, Pinterest, Pinterest is written in Django The third one, Instagram Instagram is also written in Django Majority of work of Mozilla is now being shifted to Python and they are using Django So Django is used very widely these days So the basic question arises Why Django? Why? Why should I use Django? Django, as explained in the earlier slide is a web framework So it is used to make web applications So there are many, many frameworks rather languages which are used for web applications So why new thing? First of all, it uses Python As my colleague has already showed you the advantages of using Python Python, as she told you, it was written by Guido Van and he joined Google and he actually encouraged to use Python at big scale It is open source You know the symbol What is it called as? Penguin, but it represents Linux It is called as Tux It is the logo for Linux And the one below it, Python So basically, it is open source There is vast community for Django which helps you to make your applications workable So documentation is done in a very good manner So that is also a plus point Plugability The Django is very loosely coupled The Django has one main project and apps surrounding to it It can be compared with the plugs If you do not want some functionality with it you just plug out that functionality It is as easy as that So plugability is the main feature which was absent till now in any kind of web framework Rapid and fast development Here I would like to tell a bit of history about Django Django was developed in Lawrence the magazine and newspaper industry in Kansas, United States So they shifted to Python and they had to make apps for newspaper and magazines You see, magazines and newspaper contents are very vulnerable and they change daily So what they had in their mind was they had to do rapid and fast development The content, the overall layout it used to change with the requirement and it used to change day by day So keeping in mind they developed the Django framework So the main feature being rapid and fast development Scalability and stability Since it is an open source and it has been almost 10 to 15 years Django is in the market So it is pretty stable And any one of you know what is MVC? Model, we can talk about it We will see about it in the next slide It is K, I, W, S and dry These are also two main features of Django K, I, W, S is keep it simple silly Keep it simple So the overall framework is very simple They have tried not to write too much of code and at the same time not little So keeping it simple was a main aim while developing the Django framework And D, R, Y, dry Don't repeat yourself Say you are using MySQL for retrieving your name for that matter And after few days you require same kind of functions to retrieve your surname So you need not write the whole code for name and surname both differently So Django provides such kind of apps such kind of functionality that that code can be used repetitively That is main feature is which is called as do not repeat yourself Do you know about content management systems Drupal, Jumla So it is a common misconception that Django is a CMS It is not Django is a web framework Some of its apps can be CMS like Drupal and Jumla But Django is not a CMS That is a tip point here MVC So what, what M stands for? Model So this is a model Okay V stands for view That is a good view from Boathouse from IIT Bombay only Hiranandani Skyline And C So what C stands for? Controller PS4 guys might correlate themselves with But you see this is not exactly what we are talking about It's just a part of joke It's not what we are going to see It's rather MTV Okay So it's not MVC It's MTV So in model View controller Which is being shown as MTV in Django Which is a prototype of its architecture Okay Which stands for not music television But model, templates And views And one by one I'll tell you these three concepts Okay View View is What do you see? View as in till now In many web apps Perceived as How do you see it? How do you see it? But in Django People have concentrated that What do you see? Like the one I shown The one this It is not about how it is There is one building You think of it as What exactly is shown in the picture Okay There are buildings There is lake There are grasses There is sky There is hill What is exactly being shown In the web app Is considered in the view Not how it is shown Templates For templates Now how it is shown Where should be the building Where should be the grass Where should be the hill And where should be the sky All these semantics Are explained in templates Django has its own template engine Django template engine And while displaying the contents also They use their own language Django template language Which you will eventually use Some of you will at least use it So controller Like I have shown that particular Remote controller PS4 controller What controller does is Take input from somewhere else And pass it to somewhere So somebody needs to control Like air control room Where to land How to take off Like that So in Django When the framework was designed The controller was a task For framework itself That is Django framework itself The Django framework needs to take control And see the travel the path Who needs what And provide them with that And urlconf Urlconf Urlconfigurations are passing For urlconfigurations Urls Literally passing urls from functions to And from request to response Urlconf handles that I will tell you in detail In further slides A brief introduction About installation For Django Obviously Django is written for python Python you need to have python In your system These are the commands sudo apt-get install python And you need to install pip For that Anybody know about that pip? Like apt-get apt-get It is package management Package management system only It is usually responsible For installing packages Updating it Simultaneously uninstalling it Pip provides you with that You can see in the third command Pip install Django So pip helps installing some kind of Software So after installing pip You can install Django Django and the command pip install Django And the virgin name How to see if Django is properly Installed in your system or not Is been given at the bottom That particular When you will type python Then you should import Django And this should work very fine And as shown in the command That is at the bottom So now I will be showing a Very small kind of project Which is not going to take much of your time It is very small So a project A project means a web app Web app means a website A project that does mean It is a website only So here is the command Django admin.py Start project LOTR Any LOTR funds here? Good So What it will do Is create Directories Like what is being shown here This is the parent directory That is LOTR And in that It will automatically Generate one more directory Which is called as app In that There is INIT.py file Settings.py file URLs.py And wsgif.py Those who know python Can you correlate Where Have you seen INIT.py file From where Classes Packages Packages Know anybody? It allows Initial file Initialization Used for initialization only So modules Package is nothing but Collection of modules But in Django It is usually An empty file But it represents That everything Every app Is in the form of package And These kind of Python files are being used In particular packages Okay So You may want to have a look Once again The main project being LOTR Is in the outer side The main App App is in the inner side LOTR And in the app There are four python files Okay Just make yourself clear with that Because you will be working on This kind of Hierarchy only So I will explain you In detail what they are Components As I told you earlier I90.py file is used for Initialization Settings.py Settings.py I won't be going into the details And confuse you a bit about that But settings.py file Is responsible for Database settings Which kind of database You are going to use What kind of databases Engines Are going to be provided What kind of Here there is only One app That is called as LOTR But in practical You use too many apps So you need to have Some kind of Stipulated In the stipulated point You need to Write down Which apps are going to be Used or not So Installed apps You can have the list of Apps in settings.py And from one App to other app If somebody wants to Access Data from other app So It usually Reads settings.py Third thing is URLs.py I am going to explain it in Next slide also But URLs.py Python has a very unique feature It uses regular expression To Read from the server Which URL is typed And read it And correspondingly Call the view functions Which are responsible for What do you see At the output Are you getting that URLs URLs are written In the web browser It actually reads it It actually reads it And it takes it And correspondingly It calls some views With respect to that The content is Responded with your request I will explain you later In the next slides Wgs Wsgif .py file is You need not go into details of that It is usually a system file Which is responsible for Making communication with App and the main project That is it Manage.py Manage.py is usually Responsible for It is shown in the right side Which is in the very parent Directory of the project Which manages the project only All you need to know is It manages the project very well So Writing views We have created one project Which is called as LOTR LOTR And we want to have some kind of You know To see, actually see What is happening And to see something on the web browser So All we need to do is We should write some views Okay So You can see views You have to create a new file Called as views.py In the directory Of an app In the project The app name is LOTR The same name applies to the project That is LOTR In app We have to create a views.py file Remember views.py file is Only responsible for Particular that app Which is called as LOTR The inner one So you can see I have been I have defined one function Hello And in response with that I am hello this is Bilbo So this should print on the web page Okay So next slide URL conif I told you about it Earlier So we will dive into bit Deep So URLs.py file location Is in app only This URL.py file is limited To Particular app only You can see it in the red Red color See As I told you earlier Every app is considered As class or what What he has What he has told us that it Is considered as class Or packages in my language So from my site.views Or rather LOTR.views Import hello See in views function We have defined one function Called as hello So all we are doing is Importing that function And in URLs.patterns I am telling this This Angular bracket Dollar sign Can you make something out of it Is it regular expression Is it Anybody know about regular expressions Okay So if Very few Okay So you need not go into depth Deep knowledge about regular expression As You will progress through the development You will get to know about that very well See that particular regular expression says If the URL contains hello At the end If the URL contains hello at the end Then you should call the hello function Which is written in the views.py file And Where we are responding with the hello This is bilbo statement Okay Sometimes You know regular expression gets very ugly That's what I have written in the below At the very bottom There is big regular expression So Though they are very hard to understand And hard to write also You need not care about that As soon as you will Progress through the projects You will be easily grasping that That is it So the main part Run server So In particular The very upper directory In the project directory You should be in that directory only And for running the server You should write python-manage.py Run server So this was about The very first project That is Printing hello I am bilbo at the web page So It gets very confusing At first sight What is where How it is written From where it is going to where So this is what I did in a nutshell That web browser You are seeing the URL URL Say for In this particular project We will see hello in the URL As soon as hello Is Retrieved by URL.py Or URL dispatcher It recognizes from URL's Patterns entries That If it is hello Then redirect it to views.py File Where Hello is written So It will call the hello function From views.py And it will respond With the Statement Hello this is bilbo Hello this is bilbo Is being written in the hello function In views.py Here you can see in views.py And then after interacting With views.py If at all Some kind of Advanced app Which needs to Communicate with databases It will For that particular thing They will communicate with models.py Eventually with databases Database will eventually Give the results what it What it is been asked for Then models.py Then again it Sends the request back to views.py And then again to web browser This is overall what happens With the Django This is the very basic principle What happens in Django You may use High end databases Very complex queries with it But this is what you do In Django Be clear about it We have These are some food for thoughts Models and admin interface You see as I told you earlier That this particular Django framework Was not developed in any kind Of academic institutions It was developed by a Magazine company Who were trying to Develop a web app Which changes very rapidly So Django has one very good Interface admin As you will dive more into Django Then you will come to know about it It's a very good framework about Which deals with the databases And it's a pretty good Interactive Kind of App only Which helps you Change Too many things about databases That is it And one more thing One thing I like to follow Is coding standards Coding standards You may want to go through Puppet coding standards Which are used for Django development It is always good to follow Coding standards right from the start Otherwise reading others Disaster code is Way to It takes too much time So Use the coding standards Very wisely Further Rids I would suggest you to go to Django site Where there are 4 to 5 Parts of Pulse tutorials It is called as Pulse tutorials They are very basic And very informative I guess you should go through that I guess you should go through that The Django book The Django book There is one site called Django book It has been explained in detail About Django And its components in detail So you can go through that also One of my personal favorite is Two scoops of Django The writer makes The language is so lucid That you come to know about the very Basic concepts about Django Very easily So I would suggest you to go with Two scoops of Django Otherwise Google is always at your help So this is how we unchange the Django Thank you Thank you for bearing us Thank you