Django can be broken into many components:
Models.py file: This file defines your data model by extending your single line of code into full database tables and add a pre-built administration section to manage content.
Urls.py file: It uses a regular expression to capture URL patterns for processing.
Views.py file: It is the main part of Django. The actual processing happens in view.
When a visitor lands on Django page, first Django checks the URLs pattern you have created and used the information to retrieve the view. After that view processes the request, querying your database if necessary, and passes the requested information to a template.
After that, the template renders the data in a layout you have created and displayed the page.
Q5.What are the advantages of using Django?
- The Django apps make use of very less code
- Allows quick development of websites
- Follows the DRY or the Don't Repeat Yourself Principle which means, one concept or a piece of data should live in just one place
- Consistent at low as well as high levels
- Behaviors are not implicitly assumed, they are rather explicitly specified
- SQL statements are not executed too many times and are optimized internally
- Can easily drop into raw SQL whenever required.
Q6.Is Django stable?
Yes, Django is quite stable. Many companies like Disqus, Instagram, Pinterest, and Mozilla have been using Django for many years.
Q7.What are the features available in Django web framework?
Features available in Django web framework are:
- Admin Interface (CRUD)
- Form handling
- A Session, user management, role-based permissions
- Object-relational mapping (ORM)
- Testing Framework
- Fantastic Documentation
Q8. How do you connect your Django project to the database?
Django comes with a default database which is SQLite. To connect your project to this database, 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>
Q9.What is the difference between a Project and an App?
An app is basically a Web Application that is created to do something for example, a database of employee records. A project, on the other hand, is a collection of apps of some particular website. Therefore, a single project can consist of 'n'number of apps and a single app can be in multiple projects.
Q10.What are the disadvantages of Django?
The list of disadvantages of Django:
- Django' modules are bulky.
- It is completely based on Django ORM.
- Components are deployed together.
- You must know the full system to work with it.
Q11.What are static files?
Q12.What are the inheritance styles in Django?
There are three possible inheritance styles in Django:
1) Abstract base classes: This style is used when you only want parent's class to hold information that you don't want to type out for each child model.
2) Multi-table Inheritance: This style is used if you are sub-classing an existing model and need each model to have its database table.
3) Proxy models: This style is used, if you only want to modify the Python level behavior of the model, without changing the model's fields.
Q13. How can you set up static files in Django?
There are three main things required to set up static files in Django:
1) Set STATIC_ROOT in settings.py
2) run manage.py collect static
3) set up a Static Files entry on the PythonAnywhere web tab.
Q14.What does of Django field class types do?
The Django field class types specify:
- The database column type.
- The default HTML widget to avail while rendering a form field.
- The minimal validation requirements used in Django admin.
- Automatic generated forms.
Q15.What is the usage of Django-admin.py and manage.py?
Django-admin.py: It is a Django's command line utility for administrative tasks.
Manage.py: It is an automatically created file in each Django project. It is a thin wrapper around the Django-admin.py. It has the following usage:
- It puts your project's package on sys.path.
- It sets the DJANGO_SETTING_MODULE environment variable to points to your project's setting.py file.
Q16)What are the two important parameters in signals?
Two important parameters in signals are:
- Receiver: It specifies the callback function which connected to the signal.
- Sender: It specifies a particular sender from where a signal is received.
Q17)What is Django Exception?
An exception is an abnormal event that leads to program failure. To deal with this situation, Django uses its exception classes and supports all core Python exceptions as well. Django core exceptions classes are defined in django.core.exceptions module.
Q18)What is Django Session?
A session is a mechanism to store information on the server side during the interaction with the web application. By default, session stores in the database and also allows file-based and cache based sessions.
Q19)Which foundation manages the Django web framework?
Django web framework is managed and maintained by an independent and non-profit organization named Django Software Foundation (DSF). The primary foundation goal is to promote, support, and advance the Django Web framework.
Q20)Is Django a content management system (CMS)?
No, Django is not a CMS. Instead, it is a Web framework and a programming tool that makes you able to build websites.