1"use strict";(self.webpackChunkgwoc_open_source=self.webpackChunkgwoc_open_source||[]).push([[3192],{3905:function(e,t,n){n.d(t,{Zo:function(){return p},kt:function(){return g}});var a=n(7294);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function l(e,t){if(null==e)return{};var n,a,i=function(e,t){if(null==e)return{};var n,a,i={},r=Object.keys(e);for(a=0;a<r.length;a++)n=r[a],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(a=0;a<r.length;a++)n=r[a],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var s=a.createContext({}),c=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},p=function(e){var t=c(e.components);return a.createElement(s.Provider,{value:t},e.children)},d={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},u=a.forwardRef((function(e,t){var n=e.components,i=e.mdxType,r=e.originalType,s=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),u=c(n),g=i,h=u["".concat(s,".").concat(g)]||u[g]||d[g]||r;return n?a.createElement(h,o(o({ref:t},p),{},{components:n})):a.createElement(h,o({ref:t},p))}));function g(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var r=n.length,o=new Array(r);o[0]=u;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l.mdxType="string"==typeof e?e:i,o[1]=l;for(var c=2;c<r;c++)o[c]=n[c];return a.createElement.apply(null,o)}return a.createElement.apply(null,n)}u.displayName="MDXCreateElement"},1672:function(e,t,n){n.r(t),n.d(t,{frontMatter:function(){return l},contentTitle:function(){return s},metadata:function(){return c},toc:function(){return p},default:function(){return u}});var a=n(7462),i=n(3366),r=(n(7294),n(3905)),o=["components"],l={sidebar_position:24},s="Django",c={unversionedId:"Popular_Projects/6.23_Django",id:"Popular_Projects/6.23_Django",isDocsHomePage:!1,title:"Django",description:"As we are talking about open source , Django being one , is high-level python backend framework which is not only open source but also offers us a number of features which serves as crucial part for an application . It is Built and forged by skilled and experienced developers.",source:"@site/docs/Popular_Projects/6.23_Django.md",sourceDirName:"Popular_Projects",slug:"/Popular_Projects/6.23_Django",permalink:"/docs/Popular_Projects/6.23_Django",tags:[],version:"current",sidebarPosition:24,frontMatter:{sidebar_position:24},sidebar:"tutorialSidebar",previous:{title:"Flutter",permalink:"/docs/Popular_Projects/6.22_Flutter"},next:{title:"Apache HTTP Server",permalink:"/docs/Popular_Projects/6.24_Apache"}},p=[{value:"Features that make Django , a top rated backend framework",id:"features-that-make-django--a-top-rated-backend-framework",children:[{value:"<em>High-profile site that use Django include: Disqus , Instagram , Knight Foundation , Mozilla , National Geographic etc.</em>",id:"high-profile-site-that-use-django-include-disqus--instagram--knight-foundation--mozilla--national-geographic-etc",children:[],level:5}],level:3},{value:"Installation",id:"installation",children:[{value:"1. Install Python in your root directory",id:"1--install-python-in-your-root-directory",children:[],level:4},{value:"Install Python",id:"install-python",children:[],level:4}
1,{value:"2. Create a Virtual Environment",id:"2-create-a-virtual-environment",children:[],level:4},{value:"3. Activate Virtual Environment",id:"3-activate-virtual-environment",children:[],level:4},{value:"4. Install Django",id:"4-install-django",children:[],level:4},{value:"5. Create a new Django Project",id:"5-create-a-new-django-project",children:[{value:"After locating and getting into the project directory you will this kind of project structure.",id:"after-locating-and-getting-into-the-project-directory-you-will-this-kind-of-project-structure",children:[],level:6}],level:4},{value:"6. Running the Django Project",id:"6-running-the-django-project",children:[],level:4},{value:"7. Create an Admin user",id:"7-create-an-admin-user",children:[],level:4},{value:"About Django Admin Panel",id:"about-django-admin-panel",children:[{value:"Ways to access admin panel",id:"ways-to-access-admin-panel",children:[{value:"1. After checking all the configurations in the setting file, again run the server.",id:"1-after-checking-all-the-configurations-in-the-setting-file-again-run-the-server",children:[],level:5},{value:"2. Apply migrations",id:"2-apply-migrations",children:[],level:5},{value:"3. Use the <em>/admin/</em> extension after your localhost url to access the panel page",id:"3-use-the-admin-extension-after-your-localhost-url-to-access-the-panel-page",children:[],level:5},{value:"4. Login in into the panel using the admin credentials .",id:"4-login-in-into-the-panel-using-the-admin-credentials-",children:[],level:5}],level:4}],level:3},{value:"Create Django App",id:"create-django-app",children:[{value:"1. Steps to create django app",id:"1-steps-to-create-django-app",children:[],level:4},{value:"2. Register the app in your settings file",id:"2-register-the-app-in-your-settings-file",children:[],level:4}],level:3},{value:"File Structure and its uses",id:"file-structure-and-its-uses",children:[{value:"1. Settings file",id:"1-settings-file",children:[{value:"Fields in settings file",id:"fields-in-settings-file",children:[],level:5}],level:4},{value:"2. Models File",id:"2-models-file",children:[],level:4},{value:"3. Django Views",id:"3-django-views",children:[],level:4},{value:"4. Urls",id:"4-urls",children:[],level:4},{value:"5. Templates",id:"5-templates",children:[],level:4}],level:3}],level:2}],d={toc:p};function u(e){var t=e.components,n=(0,i.Z)(e,o);return(0,r.kt)("wrapper",(0,a.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h1",{id:"django"},"Django"),(0,r.kt)("p",null,"As we are talking about open source , Django being one , is high-level python backend framework which is not only open source but also offers us a number of features which serves as crucial part for an application . It is Built and forged by skilled and experienced developers."),(0,r.kt)("img",{src:"https://i.ibb.co/QN8Z7Ts/ezgif-com-gif-maker.png",height:"250",width:"600"}),(0,r.kt)("h3",{id:"features-that-make-django--a-top-rated-backend-framework"},"Features that make Django , a top rated backend framework"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"Django with its predefined and marshal arrangement of things, makes it flexible and also provides rapid development."),(0,r.kt)("li",{parentName:"ul"},"Security is a primary concern for every professional developer , hence django provides various unbeatable features starting SQL Injection to cross-site scripting to keep things under the shelter of security."),(0,r.kt)("li",{parentName:"ul"},"Being scalable and versatile , make django easy to use and hence can easily back both large scale and small scale applications."),(0,r.kt)("li",{parentName:"ul"},"Django contains various helping task modules and libraries which can be used to handle common Web development tasks.")),(0,r.kt)("h5",{id:"high-profile-site-that-use-django-include-disqus--instagram--knight-foundation--mozilla--national-geographic-etc"},(0,r.kt)("em",{parentName:"h5"},"High-profile site that use Django include: Disqus , Instagram , Knight Foundation , Mozilla , National Geographic etc.")),(0,r.kt)("h4",{id:""}),(0,r.kt)("h2",{id:"installation"},"Installation"),(0,r.kt)("h4",{id:"1--install-python-in-your-root-directory"},"1. Install Python in your root directory"),(0,r.kt)("h4",{id:"install-python"},"Install Python"),(0,r.kt)("h1",{id:"-1"}),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sh"}
1,"pip install python\n")),(0,r.kt)("h4",{id:"2-create-a-virtual-environment"},"2. Create a Virtual Environment"),(0,r.kt)("h1",{id:"-2"}),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sh"},"python3 -m venv envname\n")),(0,r.kt)("h4",{id:"3-activate-virtual-environment"},"3. Activate Virtual Environment"),(0,r.kt)("h1",{id:"-3"}),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sh"},"source envname/bin/activate\n")),(0,r.kt)("h4",{id:"4-install-django"},"4. Install Django"),(0,r.kt)("h1",{id:"-4"}),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sh"},"pip install django\n")),(0,r.kt)("h4",{id:"5-create-a-new-django-project"},"5. Create a new Django Project"),(0,r.kt)("p",null,"Create new django project by running the following command."),(0,r.kt)("h1",{id:"-5"}),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sh"},"django-admin startproject projectname\n")),(0,r.kt)("p",null,"This will create a mysite directory in your current directory.\nGet inside that directory using the command line."),(0,r.kt)("h6",{id:"after-locating-and-getting-into-the-project-directory-you-will-this-kind-of-project-structure"},"After locating and getting into the project directory you will this kind of project structure."),(0,r.kt)("h1",{id:"-6"}),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sh"},"projectname/\n manage.py\n projectname/\n __init__.py\n settings.py\n urls.py\n asgi.py\n wsgi.py\n")),(0,r.kt)("img",{src:"https://i.ibb.co/P1VRT6Z/pr2.png"}),(0,r.kt)("h4",{id:"6-running-the-django-project"},"6. Running the Django Project"),(0,r.kt)("h1",{id:"-7"}),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sh"},"python manage.py runserver\n")),(0,r.kt)("img",{src:"https://i.ibb.co/PYg43XS/pr3.png"}),(0,r.kt)("h4",{id:"7-create-an-admin-user"},"7. Create an Admin user"),(0,r.kt)("h1",{id:"-8"}),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sh"},"python manage.py createsuperuser\n")),(0,r.kt)("h3",{id:"about-django-admin-panel"},"About Django Admin Panel"),(0,r.kt)("p",null,"Django provides built-in admin module to monitor all the CRUD Operations on the django tables(models).It provides a user-friendly interface where user can manage the content and data of the application."),(0,r.kt)("p",null,"The admin app ",(0,r.kt)("em",{parentName:"p"},"(django.contrib.admin)")," is enabled by default and already added into INSTALLED_APPS section of the settings file of the project."),(0,r.kt)("h4",{id:"ways-to-access-admin-panel"},"Ways to access admin panel"),(0,r.kt)("h5",{id:"1-after-checking-all-the-configurations-in-the-setting-file-again-run-the-server"},"1. After checking all the configurations in the setting file, again run the server."),(0,r.kt)("h1",{id:"-9"}),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sh"},"python manage.py runserver\n")),(0,r.kt)("h5",{id:"2-apply-migrations"},"2. Apply migrations"),(0,r.kt)("p",null,"By default , some changes are not migrated in the django project , hence to perform those changes , use the following commands."),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sh"},"python manage.py makemigrations\npython manage.py migrate\n")),(0,r.kt)("h5",{id:"3-use-the-admin-extension-after-your-localhost-url-to-access-the-panel-page"},"3. Use the ",(0,r.kt)("em",{parentName:"h5"},"/admin/")," extension after your localhost url to access the panel page"),(0,r.kt)("img",{src:"https://i.ibb.co/wwWn8Ft/pr4.png"}),(0,r.kt)("h5",{id:"4-login-in-into-the-panel-using-the-admin-credentials-"},"4. Login in into the panel using the admin credentials ."),(0,r.kt)("h1",{id:"-10"}),(0,r.kt)("p",null,"and voila, this is your admin-panel"),(0,r.kt)("img",{src:"https://i.ibb.co/XWcgDQ2/pr5.png"}),(0,r.kt)("h3",{id:"create-django-app"},"Create Django App"),(0,r.kt)("p",null,"Django application comprises various projects and app. It also generates an automatic base directory."),(0,r.kt)("h4",{id:"1-steps-to-create-django-app"},"1. Steps to create django app"),(0,r.kt)("h1",{id:"-11"}),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sh"}
1,"python manage.py startapp appname\n")),(0,r.kt)("h4",{id:"2-register-the-app-in-your-settings-file"},"2. Register the app in your settings file"),(0,r.kt)("p",null,"All the configurations are stored in settings.py file of the main project hence it is mandatory to register the app under the ",(0,r.kt)("em",{parentName:"p"},"INSTALLED_APP")," settings of the project."),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sh"},"INSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n 'appname',\n]\n")),(0,r.kt)("h3",{id:"file-structure-and-its-uses"},"File Structure and its uses"),(0,r.kt)("p",null,"Django has a hierarichal file structure which is easy to understand and work with . Its the file structure that makes django flexible to learn for beginners."),(0,r.kt)("h4",{id:"1-settings-file"},"1. Settings file"),(0,r.kt)("p",null,(0,r.kt)("em",{parentName:"p"},"Settings.py")," is the first file which is run when a project runs. This file contains the all the configurations starting from server and host setting to database and template settings.If you work with external apis or you want to integrate ml model in your project then , its settings.py file that comes into play first."),(0,r.kt)("h5",{id:"fields-in-settings-file"},"Fields in settings file"),(0,r.kt)("ol",null,(0,r.kt)("li",{parentName:"ol"},"Database settings"),(0,r.kt)("li",{parentName:"ol"},"Template settings"),(0,r.kt)("li",{parentName:"ol"},"Host settings"),(0,r.kt)("li",{parentName:"ol"},"login configurations"),(0,r.kt)("li",{parentName:"ol"},"static file settings"),(0,r.kt)("li",{parentName:"ol"},"Admin settings"),(0,r.kt)("li",{parentName:"ol"},"Api and other stuff")),(0,r.kt)("h4",{id:"2-models-file"},"2. Models File"),(0,r.kt)("p",null,"Django works on ",(0,r.kt)("em",{parentName:"p"},"MVT(Model View Template)")," software design pattern hence we tend to list all the tables required in the project . Model files contains table names and essential field for that respective table."),(0,r.kt)("p",null,"Django Model is a subclass of ",(0,r.kt)("em",{parentName:"p"},"django.db.models.Model")," and each field of the model class represents a database field (column)."),(0,r.kt)("p",null,"Django provides us a database-abstraction API which allows us to create, retrieve, update and delete a record from the mapped table."),(0,r.kt)("p",null,"Here is an example of the model"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sh"},"class user(models.Model):\nname = models.CharField(max_length=100)\nage = models.IntegerField(max_length=100)\n")),(0,r.kt)("p",null,"Some of the fields which we can use while creating models."),(0,r.kt)("ol",null,(0,r.kt)("li",{parentName:"ol"},"AutoField"),(0,r.kt)("li",{parentName:"ol"},"BigAutoField"),(0,r.kt)("li",{parentName:"ol"},"BigIntegerField"),(0,r.kt)("li",{parentName:"ol"},"BinaryField"),(0,r.kt)("li",{parentName:"ol"},"BooleanField"),(0,r.kt)("li",{parentName:"ol"},"ImageField"),(0,r.kt)("li",{parentName:"ol"},"CharField"),(0,r.kt)("li",{parentName:"ol"},"IntegerField"),(0,r.kt)("li",{parentName:"ol"},"EmailField"),(0,r.kt)("li",{parentName:"ol"},"DateTimeField")),(0,r.kt)("h4",{id:"3-django-views"},"3. Django Views"),(0,r.kt)("p",null,"Django view comprise views.py file where we can put all our business logic . This business logic tends work out various functionalities and logics of the application and return response to the user"),(0,r.kt)("h4",{id:"4-urls"},"4. Urls"),(0,r.kt)("p",null,"Views comes with urls. We need to route a view so as to see its response hence it is important to route a url in urls.py file of the project"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sh"},"path('index/',index,name=index)\n")),(0,r.kt)("h4",{id:"5-templates"},"5. Templates"),(0,r.kt)("p",null,"Python being a dynamic backend framework needs hypertext markup language to render the data and present it for the user's to see.Django template engine is used to separate the design from the python code and allows us to build dynamic web pages."),(0,r.kt)("p",null,"For templates to function, we need to add it in ",(0,r.kt)("em",{parentName:"p"},"INSTALLED_APPS")," section of the settings file"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-sh"}," TEMPLATES = [ \n { \n 'BACKEND': 'django.template.backends.django.DjangoTemplates', \n 'DIRS': [os.path.join(BASE_DIR,'templates')], \n 'APP_DIRS': True, \n 'OPTIONS': { \n 'context_processors': [ \n 'django.template.context_processors.debug', \n 'django.template.context_processors.request', \n 'django.contrib.auth.context_processors.auth', \n 'django.contrib.messages.context_processors.messages', \n ], \n }, \n }, \n ] \n")),(0,r.kt)("p",null,"And , here we are , starting and working with top rated and flexible backend framework.Everything technology needs to researched carefully hence if you want to learn more about this amazing frameworks , just head towards its documentation."),(0,r.kt)("p",null,"Thank You!"))}u.isMDXComponent=!0}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.