SlideShare uma empresa Scribd logo
1 de 55
www.edureka.cowww.edureka.co
What is the difference
between Flask and
Django?
01
www.edureka.co/python
Comparison Factor Django Flask
Project Type Supports large projects Built for smaller projects
Templates, Admin and
ORM
Built-in Requires installation
Ease of Learning
Requires more learning and
practice
Easy to learn
Flexibility
Allows complete web
development without the
need for third-party tools
More flexible as the user
can select any third-party
tools according to their
choice and requirements
Visual Debugging
Does not support Visual
Debug
Supports Visual Debug
Type of framework Batteries included Simple, lightweight
Bootstrapping-tool Built-it Not available
www.edureka.cowww.edureka.co
What is Django?02
www.edureka.co/python
• Web development framework
• Free and open-source
• Django is maintained by a non-profit organization called the
Django Software Foundation
• Goal is to enable Web Development quickly and with ease
www.edureka.cowww.edureka.co
Name some companies
that make use of
Django?
03
www.edureka.co/python
Some of the companies that make use of Django:
• Instagram
• DISCUS
• Mozilla Firefox
• YouTube
• Pinterest
• Reddit
www.edureka.co
What are the features
of Django?04
www.edureka.co/python
Fast
Tons of
Packages
Secure
Scalable
Versatile
www.edureka.cowww.edureka.co
How do you check for
the version of Django
installed on your
system?
05
www.edureka.co/python
Open the command prompt and enter the
following command:
→ python -m django –version
You can also use the following:
import django
print(django.get_version())
www.edureka.cowww.edureka.co
What are the
advantages of using
Django?
06
www.edureka.co/python
• Django’s stack is loosely coupled
• Very less code
• Quick development
• Follows Don’t Repeat Yourself Principle
• Consistent
• Behaviours are explicitly specified
• SQL statements are not executed too many
times
• Can easily drop into raw SQL
• Flexibility while using URL’s
www.edureka.cowww.edureka.co
Explain Django
architecture.07
www.edureka.co/python
• View describes the data presented to the
user
• Templates deal with the presentation of data
• Controller is Django itself which sends the
request to the appropriate view
www.edureka.cowww.edureka.co
Give a brief about
‘django-admin’.08
www.edureka.co/python
Task Command
To display the usage information django-admin help
List of available commands django-admin help –command
To display the description of a given command django-admin help <command>
Determining the version of Django django-admin version
Creating new migrations django-admin makemigrations
Synchronizing the database state django-admin migrate
Starting the development server django-admin runserver
Sending a test email django-admin sendtestemail
To start the Python interactive interpreter django-admin shell
To show all the migrations in your project django-admin showmigrations
django-admin is the command-line utility of Django for
administrative tasks
www.edureka.cowww.edureka.co
How do you connect
your Django project to
the database?
09
www.edureka.co/python
Use the following commands:
→ python manage.py migrate
→ python manage.py makemigrations
→ python manage.py sqlmigrate (name of
the app followed by the generated id)
www.edureka.cowww.edureka.co
What are the various
files that are created
when you create a
Django Project? Explain
briefly.
10
www.edureka.co/python
File Name Description
manage.py A command-line utility
__init__.py
An empty file that tells Python that the
current directory should be considered as
a Python package
settings.py Settings for the current project
urls.py URL’s for the current project
wsgi.py
Entry-point for the web servers to serve
the project you have created
www.edureka.cowww.edureka.co
What are ‘Models’?11
www.edureka.co/python
• Single and definitive source for information
about your data
• Consists of all the essential fields and
behaviours
• Each model will map to a single specific
database table
• In Django, models serve as the abstraction
layer
• They are a subclass of the
django.db.models.Model
www.edureka.cowww.edureka.co
What are ‘views’?12
www.edureka.co/python
• Serve the purpose of encapsulation
• They encapsulate the logic
• Either return an HttpResponse or raise an
exception such as Http404
• Can read records from the database
• Can delegate to the templates, generate a
PDF file, etc.
www.edureka.cowww.edureka.co
What are ‘templates’?13
www.edureka.co/python
• Renders the information to be presented to
the user
• Can generate HTML dynamically
• HTML consists of both static as well as
dynamic
• You can have any number of templates
• It is also fine to have none of them
www.edureka.cowww.edureka.co
What is the difference
between a Project and
an App?
14
www.edureka.co/python
• An app is a Web Application that is created to
do something
• A project is a collection of apps
• Therefore, a single project can consist of n
number of apps and an app can be in any
project
www.edureka.cowww.edureka.co
What are the different
inheritance styles in
Django?
15
www.edureka.co/python
Inheritance style Description
Abstract base classes
Used when you want to use the parent class
to hold information
Multi-table inheritance
Used when you have to subclass an existing
model
Proxy models
Used if you only want to modify the Python-
level behaviour of a model
www.edureka.cowww.edureka.co
What are static files?16
www.edureka.co/python
• Static files are files that serve the purpose of
additional files such as the CSS files, images
or JavaScript files
• These files are managed by
django.contrib.staticfiles
• These files are created within the project app
directory
www.edureka.cowww.edureka.co
What are ‘signals’?17
www.edureka.co/python
Signal Description
django.db.models.signals.pre_save
django.db.models.signals.post_save
Sent before or after a
model’s save() method is
called
django.db.models.signals.pre_delet
e
django.db.models.signals.post_dele
te
Sent before or after a
model’s delete() method or
queryset’s delete() method
is called
django.db.models.signals.m2m_cha
nged
Sent when Django starts or
finishes an HTTP request
www.edureka.cowww.edureka.co
Briefly explain Django
Field Class.18
www.edureka.co/python
• ‘Field’ is an abstract class that represents a
column in the database table
• The Field class is a subclass
of RegisterLookupMixin
• In Django, these fields are used to create
database tables
• Fields are fundamental pieces in different
Django APIs such as models and querysets.
www.edureka.cowww.edureka.co
How to do you create a
Django project?19
www.edureka.co/python
To create a Django project, cd into the directory
where you would like to create your project and
type the following command:
→ django-admin startproject xyz
NOTE: Here, xyz is the name of the project.
You can give any name that you desire.
www.edureka.cowww.edureka.co
What is mixin?20
www.edureka.co/python
• Mixin is a type of multiple inheritance
• Can combine behaviours and attributes of
more than one parent class
• Excellent way to reuse code from multiple
classes
• For example, generic class based views
consist of a mixin called
TemplateResponseMixin whose purpose is to
define render_to_response() method
• When this is combined with a class present
in the View, the result will be a TemplateView
class.
www.edureka.cowww.edureka.co
What are ‘sessions’?21
www.edureka.co/python
• Allows you to store and retrieve arbitrary data
based on the per-site-visitors
• This framework stores data on the server-
side
• Takes care of sending and receiving cookies
• These cookies consist of a session ID but not
the actual data itself
www.edureka.cowww.edureka.co
What is context?
22
www.edureka.co/python
The context in Django is a dictionary mapping
template variable name given to Python
objects.
www.edureka.cowww.edureka.co
When can you use
iterators in Django
ORM?
23
www.edureka.co/python
• Iterators in Python are containers that consist
of a countable number of elements
• Any object that is an iterator implements two
methods (__init__() and the
__next__() methods)
• The best situation to use iterators is when
you have to process results that will require a
large amount of memory space
• You can make use of the iterator() method
www.edureka.cowww.edureka.co
Explain the caching
strategies of Django?24
www.edureka.co/python
Strategy Description
Memcached Memory-based cache server
Filesystem caching
Cache values are stored as separate
files
Local-memory caching
Default cache in case you have not
specified any other
Database caching
Cache data will be stored in the
database
www.edureka.cowww.edureka.co
Explain the use of
Middlewares in Django.25
www.edureka.co/python
• Middleware is a framework that is a light and
low-level plugin system for altering Django’s
input and output globally
• It is a framework of hooks into the request/
response processing
• Each component in middleware has some
particular task
• For example,
the AuthenticationMiddleware is used to
associate users with requests using sessions
• Django provides many other middleware
such as cache middleware, common
middleware , GZip middleware, etc
www.edureka.cowww.edureka.co
What is the significance
of manage.py file in
Django?
26
www.edureka.co/python
• manage,py file is automatically generated
• It is a command-line utility that helps you to
interact with your Django project
• It does the same things as django-admin
• Also sets the
DJANGO_SETTINGS_MODULE
environment variable
• It is better to make use of manage,py rather
than the django-admin
www.edureka.cowww.edureka.co
Explain the use of
migrate command in
Django?
27
www.edureka.co/python
• Migrations are used to propagate changes
made to the models
• The migrate command is used to apply or
unapply migrations
• Synchronizes the current set of models and
migrations with the database state
• Can be used with or without parameters
• In case you do not specify any parameter, all
apps will have all their migrations running
www.edureka.cowww.edureka.co
How to view and filter
items from the
database?
28
www.edureka.co/python
In order to view all the items from your database, you
can make use of the all() function in your interactive
shell as follows:
→ XYZ.objects.all()
To filter out some element from your database, you
either use the get() method or the filter method as
follows:
→ XYZ.objects.filter(pk=1)
→ XYZ.objects.get(id=1)
www.edureka.cowww.edureka.co
Explain how a request is
processed in Django?29
www.edureka.co/python
• Django first determines which root URLconf module is
to be used
• That particular Python module is loaded
• Then, Django looks for the variable urlpatterns
• URL patterns are run by Django, and it stops at the first
match of the requested URL
• Once that is done, the Django then imports and calls
the given view
• In case none of the URLs match the requested URL,
Django invokes an error-handling view
www.edureka.cowww.edureka.co
How did Django come
into existence?30
www.edureka.co/python
• World Online developers started using Python to
develop websites
• As they went on building intensive, richly interactive
sites, they began to pull out a generic Web
development framework that allowed them to build
Web applications more and more quickly
• In summer 2005, World Online decided to open-
source the resulting software, Django
www.edureka.cowww.edureka.co
Explain how to use file-
based sessions?31
www.edureka.co/python
In order to make use of file-based sessions, you will need
to set the SESSION_ENGINE setting to
“django.contrib.sessions.backends.file”.
www.edureka.cowww.edureka.co
Explain the Django URLs
in brief?32
www.edureka.co/python
Django allows you to design your own URLs. In order to
create URLs for your app, you will need to create a Python
module informally which is called the URLconf or URL
configuration. The length of this mapping can be as long or
short as required and can also reference other mappings.
When processing a request, the requested URL is matched
with the URLs present in the urls.py file and the
corresponding view is retrieved.
www.edureka.cowww.edureka.co
Give the exception
classes present in
Django.
33
www.edureka.co/python
Exception Description
AppRegistryNotReady
Raised when you try to use your models
before the app loading process
ObjectDoesNotExist
This is the base class for DoesNotExist
exceptions
EmptyResultSet
This exception may be raised if a query
won’t return any result
FieldDoesNotExist
This exception is raised by a model’s
_meta.get_field() function in case the
requested field does not exist
MultipleObjectsReturned
This is raised by a query if multiple objects
are returned and only one object was
expected
www.edureka.cowww.edureka.co
Is Django stable?34
www.edureka.co/python
Yes, it’s quite stable. Companies like Disqus, Instagram,
Pinterest, and Mozilla have been using Django for many years.
Sites built on Django have weathered traffic spikes of over 50
thousand hits per second.
www.edureka.cowww.edureka.co
Does Django scale?35
www.edureka.co/python
Yes. Compared to development time, hardware is cheap, and so
Django is designed to take advantage of as much hardware as you
can throw at it. Django uses a “shared-nothing” architecture, which
means you can add hardware at any level such as database servers,
caching servers or Web/application servers.
www.edureka.cowww.edureka.co
Is Django a CMS?36
www.edureka.co/python
No, Django is not a CMS, or any sort of “turnkey product” in and
of itself. It’s a Web framework; it’s a programming tool that lets
you build websites. For example, it doesn’t make much sense to
compare Django to something like Drupal, because Django is
something you use to create things like Drupal.
www.edureka.cowww.edureka.co
What Python version
should be used with
Django?
37
www.edureka.co/python
Django Version Python Versions
1.11 2.7, 3.4, 3.5, 3.6, 3.7 (added in 1.11.17)
2.0 3.4, 3.5, 3.6, 3.7
2.1, 2.2 3.5, 3.6, 3.7
www.edureka.cowww.edureka.co
Does Django support
NoSQL?38
www.edureka.co/python
Officially, Django does not support NoSQL databases.
However, there are third-party projects, such as Django non-
rel, that allow NoSQL functionality in Django.
www.edureka.cowww.edureka.co
How can you
customize the
functionality of the
Django admin
interface?
39
www.edureka.co/python
You can piggyback on top of an add/ change form that is
automatically generated by Django, you can add JavaScript
modules using the js parameter which is a list of URLs that
point to the JavaScript modules. To do more than just playing
around with from, you can exclusively write views for the
admin.
www.edureka.cowww.edureka.co
Is Django better than
Flask?40
www.edureka.co/python
The answer to this question basically depends on the user’s need.
Django is a framework that allows you to build large projects. Flask is
used to build smaller websites but flask is much easier to learn and use
compared to Django. Django is a full-fledged framework but Flask is a
lightweight framework that allows you to install third-party tools. So in
case the need is very heavy, the answer is definitely, Django.
www.edureka.cowww.edureka.co
Give an example of a
Django view.41
www.edureka.co/python
A view in Django either returns an HttpResponse or
raises an exception such as Http404
www.edureka.cowww.edureka.co
What should be done in
case you get a message
saying “Please enter the
correct username and
password” even after
entering the right
details to log in to the
admin section?
42
www.edureka.co/python
Do the following if you have entered the right details but still not
able to login to the admin site:
Set is_active and is_staff to True
The admin site allows only those users for whom these values
are set to True.
www.edureka.cowww.edureka.co
What should be done in
case you re not able to
log in even after
entering the right
details and you get no
error message?
43
www.edureka.co/python
The login cookie is not being set rightly. This happens if
the domain of the cookie sent out by Django does not
match the domain in your browser.
Change SESSION_COOKIE_DOMAIN setting to match
that of your browser.
www.edureka.cowww.edureka.co
How can you limit
admin access so that
the objects can only be
edited by those users
who have created
them?
44
www.edureka.co/python
Django’s ModelAdmin class provides customization hooks using
which, you can control the visibility and editability of objects in
the admin. To do this, you can use
the get_queryset() and has_change_permission().
www.edureka.cowww.edureka.co
What to do when you
don’t see all objects
appearing on the admin
site?
45
www.edureka.co/python
Inconsistent row counts are a result of missing Foreign Key values or
if the Foreign Key field is set to null=False. If the ForeignKey points to
a record that does not exist and if that foreign is present in
the list_display method, the record will not be shown the admin
changelist.
www.edureka.cowww.edureka.co
What do you mean by
the csrf_token?46
www.edureka.co/python
The csrf_token is used for protection against Cross-Site Request Forgeries.
This kind of attack takes place when a malicious website consists of a link,
some JavaScript or a form whose aim is to perform some action on your
website by using the login credentials of a genuine user.
www.edureka.cowww.edureka.co
How can you see the
raw SQL queries that
Django is running?
47
www.edureka.co/python
Make sure that your DEBUG setting is set to
True. Then, type the following commands:
www.edureka.cowww.edureka.co
Is it mandatory to use
the model/ database
layer?
48
www.edureka.co/python
No. The model/ database layer is actually decoupled from
the rest of the framework.
www.edureka.cowww.edureka.co
How to make a variable
available to all the
templates?
49
www.edureka.co/python
You can make use of the RequestContext in case all your
templates require the same objects .This method takes an
HttpRequest as its first parameter and it automatically
populates s the context with a few variables
www.edureka.cowww.edureka.co
Does Django support
multiple-column
Primary Keys?
50
www.edureka.co/python
No. Django only supports single-column
primary keys.
www.edureka.co/python

Mais conteúdo relacionado

Mais procurados

Introduction to django
Introduction to djangoIntroduction to django
Introduction to django
Ilian Iliev
 
Django Framework and Application Structure
Django Framework and Application StructureDjango Framework and Application Structure
Django Framework and Application Structure
SEONGTAEK OH
 

Mais procurados (20)

Introduction to django framework
Introduction to django frameworkIntroduction to django framework
Introduction to django framework
 
Python Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaPython Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | Edureka
 
Django PPT.pptx
Django PPT.pptxDjango PPT.pptx
Django PPT.pptx
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for Beginners
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python Developers
 
Introduction to django
Introduction to djangoIntroduction to django
Introduction to django
 
Introduction To Django
Introduction To DjangoIntroduction To Django
Introduction To Django
 
Python/Flask Presentation
Python/Flask PresentationPython/Flask Presentation
Python/Flask Presentation
 
Learn Python Programming | Python Programming - Step by Step | Python for Beg...
Learn Python Programming | Python Programming - Step by Step | Python for Beg...Learn Python Programming | Python Programming - Step by Step | Python for Beg...
Learn Python Programming | Python Programming - Step by Step | Python for Beg...
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 
Introduction to the Python
Introduction to the PythonIntroduction to the Python
Introduction to the Python
 
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Python - the basics
Python - the basicsPython - the basics
Python - the basics
 
JSON-LD
JSON-LDJSON-LD
JSON-LD
 
Python Programming Essentials - M27 - Logging module
Python Programming Essentials - M27 - Logging modulePython Programming Essentials - M27 - Logging module
Python Programming Essentials - M27 - Logging module
 
Django
DjangoDjango
Django
 
django
djangodjango
django
 
Django Framework and Application Structure
Django Framework and Application StructureDjango Framework and Application Structure
Django Framework and Application Structure
 
Dynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEMDynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEM
 

Semelhante a Django interview Questions| Edureka

0506-django-web-framework-for-python.pdf
0506-django-web-framework-for-python.pdf0506-django-web-framework-for-python.pdf
0506-django-web-framework-for-python.pdf
radhianiedjan1
 
Django Article V0
Django Article V0Django Article V0
Django Article V0
Udi Bauman
 

Semelhante a Django interview Questions| Edureka (20)

Django Workflow and Architecture
Django Workflow and ArchitectureDjango Workflow and Architecture
Django Workflow and Architecture
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Django Documentation
Django DocumentationDjango Documentation
Django Documentation
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docx
 
Django course
Django courseDjango course
Django course
 
What are the basic key points to focus on while learning Full-stack web devel...
What are the basic key points to focus on while learning Full-stack web devel...What are the basic key points to focus on while learning Full-stack web devel...
What are the basic key points to focus on while learning Full-stack web devel...
 
Django Frequently Asked Interview Questions
Django Frequently Asked Interview QuestionsDjango Frequently Asked Interview Questions
Django Frequently Asked Interview Questions
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Concepts and applications of Django.pptx
Concepts and applications of Django.pptxConcepts and applications of Django.pptx
Concepts and applications of Django.pptx
 
Introduction to django
Introduction to djangoIntroduction to django
Introduction to django
 
Django part 1
Django part 1Django part 1
Django part 1
 
Django framework
Django frameworkDjango framework
Django framework
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگو
 
Sahil_18118_IOT-ppt.pptx
Sahil_18118_IOT-ppt.pptxSahil_18118_IOT-ppt.pptx
Sahil_18118_IOT-ppt.pptx
 
Python & Django
Python & DjangoPython & Django
Python & Django
 
0506-django-web-framework-for-python.pdf
0506-django-web-framework-for-python.pdf0506-django-web-framework-for-python.pdf
0506-django-web-framework-for-python.pdf
 
Django by rj
Django by rjDjango by rj
Django by rj
 
Django Article V0
Django Article V0Django Article V0
Django Article V0
 
Django
DjangoDjango
Django
 
Implementing a Symfony Based CMS in a Publishing Company
Implementing a Symfony Based CMS in a Publishing CompanyImplementing a Symfony Based CMS in a Publishing Company
Implementing a Symfony Based CMS in a Publishing Company
 

Mais de Edureka!

Mais de Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Django interview Questions| Edureka

  • 1.
  • 2. www.edureka.cowww.edureka.co What is the difference between Flask and Django? 01 www.edureka.co/python Comparison Factor Django Flask Project Type Supports large projects Built for smaller projects Templates, Admin and ORM Built-in Requires installation Ease of Learning Requires more learning and practice Easy to learn Flexibility Allows complete web development without the need for third-party tools More flexible as the user can select any third-party tools according to their choice and requirements Visual Debugging Does not support Visual Debug Supports Visual Debug Type of framework Batteries included Simple, lightweight Bootstrapping-tool Built-it Not available
  • 3. www.edureka.cowww.edureka.co What is Django?02 www.edureka.co/python • Web development framework • Free and open-source • Django is maintained by a non-profit organization called the Django Software Foundation • Goal is to enable Web Development quickly and with ease
  • 4. www.edureka.cowww.edureka.co Name some companies that make use of Django? 03 www.edureka.co/python Some of the companies that make use of Django: • Instagram • DISCUS • Mozilla Firefox • YouTube • Pinterest • Reddit
  • 5. www.edureka.co What are the features of Django?04 www.edureka.co/python Fast Tons of Packages Secure Scalable Versatile
  • 6. www.edureka.cowww.edureka.co How do you check for the version of Django installed on your system? 05 www.edureka.co/python Open the command prompt and enter the following command: → python -m django –version You can also use the following: import django print(django.get_version())
  • 7. www.edureka.cowww.edureka.co What are the advantages of using Django? 06 www.edureka.co/python • Django’s stack is loosely coupled • Very less code • Quick development • Follows Don’t Repeat Yourself Principle • Consistent • Behaviours are explicitly specified • SQL statements are not executed too many times • Can easily drop into raw SQL • Flexibility while using URL’s
  • 8. www.edureka.cowww.edureka.co Explain Django architecture.07 www.edureka.co/python • View describes the data presented to the user • Templates deal with the presentation of data • Controller is Django itself which sends the request to the appropriate view
  • 9. www.edureka.cowww.edureka.co Give a brief about ‘django-admin’.08 www.edureka.co/python Task Command To display the usage information django-admin help List of available commands django-admin help –command To display the description of a given command django-admin help <command> Determining the version of Django django-admin version Creating new migrations django-admin makemigrations Synchronizing the database state django-admin migrate Starting the development server django-admin runserver Sending a test email django-admin sendtestemail To start the Python interactive interpreter django-admin shell To show all the migrations in your project django-admin showmigrations django-admin is the command-line utility of Django for administrative tasks
  • 10. www.edureka.cowww.edureka.co How do you connect your Django project to the database? 09 www.edureka.co/python Use the following commands: → python manage.py migrate → python manage.py makemigrations → python manage.py sqlmigrate (name of the app followed by the generated id)
  • 11. www.edureka.cowww.edureka.co What are the various files that are created when you create a Django Project? Explain briefly. 10 www.edureka.co/python File Name Description manage.py A command-line utility __init__.py An empty file that tells Python that the current directory should be considered as a Python package settings.py Settings for the current project urls.py URL’s for the current project wsgi.py Entry-point for the web servers to serve the project you have created
  • 12. www.edureka.cowww.edureka.co What are ‘Models’?11 www.edureka.co/python • Single and definitive source for information about your data • Consists of all the essential fields and behaviours • Each model will map to a single specific database table • In Django, models serve as the abstraction layer • They are a subclass of the django.db.models.Model
  • 13. www.edureka.cowww.edureka.co What are ‘views’?12 www.edureka.co/python • Serve the purpose of encapsulation • They encapsulate the logic • Either return an HttpResponse or raise an exception such as Http404 • Can read records from the database • Can delegate to the templates, generate a PDF file, etc.
  • 14. www.edureka.cowww.edureka.co What are ‘templates’?13 www.edureka.co/python • Renders the information to be presented to the user • Can generate HTML dynamically • HTML consists of both static as well as dynamic • You can have any number of templates • It is also fine to have none of them
  • 15. www.edureka.cowww.edureka.co What is the difference between a Project and an App? 14 www.edureka.co/python • An app is a Web Application that is created to do something • A project is a collection of apps • Therefore, a single project can consist of n number of apps and an app can be in any project
  • 16. www.edureka.cowww.edureka.co What are the different inheritance styles in Django? 15 www.edureka.co/python Inheritance style Description Abstract base classes Used when you want to use the parent class to hold information Multi-table inheritance Used when you have to subclass an existing model Proxy models Used if you only want to modify the Python- level behaviour of a model
  • 17.
  • 18. www.edureka.cowww.edureka.co What are static files?16 www.edureka.co/python • Static files are files that serve the purpose of additional files such as the CSS files, images or JavaScript files • These files are managed by django.contrib.staticfiles • These files are created within the project app directory
  • 19. www.edureka.cowww.edureka.co What are ‘signals’?17 www.edureka.co/python Signal Description django.db.models.signals.pre_save django.db.models.signals.post_save Sent before or after a model’s save() method is called django.db.models.signals.pre_delet e django.db.models.signals.post_dele te Sent before or after a model’s delete() method or queryset’s delete() method is called django.db.models.signals.m2m_cha nged Sent when Django starts or finishes an HTTP request
  • 20. www.edureka.cowww.edureka.co Briefly explain Django Field Class.18 www.edureka.co/python • ‘Field’ is an abstract class that represents a column in the database table • The Field class is a subclass of RegisterLookupMixin • In Django, these fields are used to create database tables • Fields are fundamental pieces in different Django APIs such as models and querysets.
  • 21. www.edureka.cowww.edureka.co How to do you create a Django project?19 www.edureka.co/python To create a Django project, cd into the directory where you would like to create your project and type the following command: → django-admin startproject xyz NOTE: Here, xyz is the name of the project. You can give any name that you desire.
  • 22. www.edureka.cowww.edureka.co What is mixin?20 www.edureka.co/python • Mixin is a type of multiple inheritance • Can combine behaviours and attributes of more than one parent class • Excellent way to reuse code from multiple classes • For example, generic class based views consist of a mixin called TemplateResponseMixin whose purpose is to define render_to_response() method • When this is combined with a class present in the View, the result will be a TemplateView class.
  • 23. www.edureka.cowww.edureka.co What are ‘sessions’?21 www.edureka.co/python • Allows you to store and retrieve arbitrary data based on the per-site-visitors • This framework stores data on the server- side • Takes care of sending and receiving cookies • These cookies consist of a session ID but not the actual data itself
  • 24. www.edureka.cowww.edureka.co What is context? 22 www.edureka.co/python The context in Django is a dictionary mapping template variable name given to Python objects.
  • 25. www.edureka.cowww.edureka.co When can you use iterators in Django ORM? 23 www.edureka.co/python • Iterators in Python are containers that consist of a countable number of elements • Any object that is an iterator implements two methods (__init__() and the __next__() methods) • The best situation to use iterators is when you have to process results that will require a large amount of memory space • You can make use of the iterator() method
  • 26. www.edureka.cowww.edureka.co Explain the caching strategies of Django?24 www.edureka.co/python Strategy Description Memcached Memory-based cache server Filesystem caching Cache values are stored as separate files Local-memory caching Default cache in case you have not specified any other Database caching Cache data will be stored in the database
  • 27. www.edureka.cowww.edureka.co Explain the use of Middlewares in Django.25 www.edureka.co/python • Middleware is a framework that is a light and low-level plugin system for altering Django’s input and output globally • It is a framework of hooks into the request/ response processing • Each component in middleware has some particular task • For example, the AuthenticationMiddleware is used to associate users with requests using sessions • Django provides many other middleware such as cache middleware, common middleware , GZip middleware, etc
  • 28. www.edureka.cowww.edureka.co What is the significance of manage.py file in Django? 26 www.edureka.co/python • manage,py file is automatically generated • It is a command-line utility that helps you to interact with your Django project • It does the same things as django-admin • Also sets the DJANGO_SETTINGS_MODULE environment variable • It is better to make use of manage,py rather than the django-admin
  • 29. www.edureka.cowww.edureka.co Explain the use of migrate command in Django? 27 www.edureka.co/python • Migrations are used to propagate changes made to the models • The migrate command is used to apply or unapply migrations • Synchronizes the current set of models and migrations with the database state • Can be used with or without parameters • In case you do not specify any parameter, all apps will have all their migrations running
  • 30. www.edureka.cowww.edureka.co How to view and filter items from the database? 28 www.edureka.co/python In order to view all the items from your database, you can make use of the all() function in your interactive shell as follows: → XYZ.objects.all() To filter out some element from your database, you either use the get() method or the filter method as follows: → XYZ.objects.filter(pk=1) → XYZ.objects.get(id=1)
  • 31. www.edureka.cowww.edureka.co Explain how a request is processed in Django?29 www.edureka.co/python • Django first determines which root URLconf module is to be used • That particular Python module is loaded • Then, Django looks for the variable urlpatterns • URL patterns are run by Django, and it stops at the first match of the requested URL • Once that is done, the Django then imports and calls the given view • In case none of the URLs match the requested URL, Django invokes an error-handling view
  • 32. www.edureka.cowww.edureka.co How did Django come into existence?30 www.edureka.co/python • World Online developers started using Python to develop websites • As they went on building intensive, richly interactive sites, they began to pull out a generic Web development framework that allowed them to build Web applications more and more quickly • In summer 2005, World Online decided to open- source the resulting software, Django
  • 33.
  • 34. www.edureka.cowww.edureka.co Explain how to use file- based sessions?31 www.edureka.co/python In order to make use of file-based sessions, you will need to set the SESSION_ENGINE setting to “django.contrib.sessions.backends.file”.
  • 35. www.edureka.cowww.edureka.co Explain the Django URLs in brief?32 www.edureka.co/python Django allows you to design your own URLs. In order to create URLs for your app, you will need to create a Python module informally which is called the URLconf or URL configuration. The length of this mapping can be as long or short as required and can also reference other mappings. When processing a request, the requested URL is matched with the URLs present in the urls.py file and the corresponding view is retrieved.
  • 36. www.edureka.cowww.edureka.co Give the exception classes present in Django. 33 www.edureka.co/python Exception Description AppRegistryNotReady Raised when you try to use your models before the app loading process ObjectDoesNotExist This is the base class for DoesNotExist exceptions EmptyResultSet This exception may be raised if a query won’t return any result FieldDoesNotExist This exception is raised by a model’s _meta.get_field() function in case the requested field does not exist MultipleObjectsReturned This is raised by a query if multiple objects are returned and only one object was expected
  • 37. www.edureka.cowww.edureka.co Is Django stable?34 www.edureka.co/python Yes, it’s quite stable. Companies like Disqus, Instagram, Pinterest, and Mozilla have been using Django for many years. Sites built on Django have weathered traffic spikes of over 50 thousand hits per second.
  • 38. www.edureka.cowww.edureka.co Does Django scale?35 www.edureka.co/python Yes. Compared to development time, hardware is cheap, and so Django is designed to take advantage of as much hardware as you can throw at it. Django uses a “shared-nothing” architecture, which means you can add hardware at any level such as database servers, caching servers or Web/application servers.
  • 39. www.edureka.cowww.edureka.co Is Django a CMS?36 www.edureka.co/python No, Django is not a CMS, or any sort of “turnkey product” in and of itself. It’s a Web framework; it’s a programming tool that lets you build websites. For example, it doesn’t make much sense to compare Django to something like Drupal, because Django is something you use to create things like Drupal.
  • 40. www.edureka.cowww.edureka.co What Python version should be used with Django? 37 www.edureka.co/python Django Version Python Versions 1.11 2.7, 3.4, 3.5, 3.6, 3.7 (added in 1.11.17) 2.0 3.4, 3.5, 3.6, 3.7 2.1, 2.2 3.5, 3.6, 3.7
  • 41. www.edureka.cowww.edureka.co Does Django support NoSQL?38 www.edureka.co/python Officially, Django does not support NoSQL databases. However, there are third-party projects, such as Django non- rel, that allow NoSQL functionality in Django.
  • 42. www.edureka.cowww.edureka.co How can you customize the functionality of the Django admin interface? 39 www.edureka.co/python You can piggyback on top of an add/ change form that is automatically generated by Django, you can add JavaScript modules using the js parameter which is a list of URLs that point to the JavaScript modules. To do more than just playing around with from, you can exclusively write views for the admin.
  • 43. www.edureka.cowww.edureka.co Is Django better than Flask?40 www.edureka.co/python The answer to this question basically depends on the user’s need. Django is a framework that allows you to build large projects. Flask is used to build smaller websites but flask is much easier to learn and use compared to Django. Django is a full-fledged framework but Flask is a lightweight framework that allows you to install third-party tools. So in case the need is very heavy, the answer is definitely, Django.
  • 44. www.edureka.cowww.edureka.co Give an example of a Django view.41 www.edureka.co/python A view in Django either returns an HttpResponse or raises an exception such as Http404
  • 45. www.edureka.cowww.edureka.co What should be done in case you get a message saying “Please enter the correct username and password” even after entering the right details to log in to the admin section? 42 www.edureka.co/python Do the following if you have entered the right details but still not able to login to the admin site: Set is_active and is_staff to True The admin site allows only those users for whom these values are set to True.
  • 46. www.edureka.cowww.edureka.co What should be done in case you re not able to log in even after entering the right details and you get no error message? 43 www.edureka.co/python The login cookie is not being set rightly. This happens if the domain of the cookie sent out by Django does not match the domain in your browser. Change SESSION_COOKIE_DOMAIN setting to match that of your browser.
  • 47. www.edureka.cowww.edureka.co How can you limit admin access so that the objects can only be edited by those users who have created them? 44 www.edureka.co/python Django’s ModelAdmin class provides customization hooks using which, you can control the visibility and editability of objects in the admin. To do this, you can use the get_queryset() and has_change_permission().
  • 48. www.edureka.cowww.edureka.co What to do when you don’t see all objects appearing on the admin site? 45 www.edureka.co/python Inconsistent row counts are a result of missing Foreign Key values or if the Foreign Key field is set to null=False. If the ForeignKey points to a record that does not exist and if that foreign is present in the list_display method, the record will not be shown the admin changelist.
  • 49.
  • 50. www.edureka.cowww.edureka.co What do you mean by the csrf_token?46 www.edureka.co/python The csrf_token is used for protection against Cross-Site Request Forgeries. This kind of attack takes place when a malicious website consists of a link, some JavaScript or a form whose aim is to perform some action on your website by using the login credentials of a genuine user.
  • 51. www.edureka.cowww.edureka.co How can you see the raw SQL queries that Django is running? 47 www.edureka.co/python Make sure that your DEBUG setting is set to True. Then, type the following commands:
  • 52. www.edureka.cowww.edureka.co Is it mandatory to use the model/ database layer? 48 www.edureka.co/python No. The model/ database layer is actually decoupled from the rest of the framework.
  • 53. www.edureka.cowww.edureka.co How to make a variable available to all the templates? 49 www.edureka.co/python You can make use of the RequestContext in case all your templates require the same objects .This method takes an HttpRequest as its first parameter and it automatically populates s the context with a few variables
  • 54. www.edureka.cowww.edureka.co Does Django support multiple-column Primary Keys? 50 www.edureka.co/python No. Django only supports single-column primary keys.