Skip to content

Commit 7dde115

Browse files
committed
Added django questions
1 parent 665b401 commit 7dde115

1 file changed

Lines changed: 133 additions & 1 deletion

File tree

docs/index.md

Lines changed: 133 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,4 +1254,136 @@ python manage.py migrate
12541254
python mange.py my_manage_command
12551255
python manage.py createsuperuser
12561256
python manage.py shell
1257-
```
1257+
```
1258+
1259+
1) Explain what is Django?
1260+
1261+
Django is a web framework in python to develop a web application in python.
1262+
1263+
2) Mention what are the features available in Django?
1264+
1265+
Features available in Django are
1266+
1267+
Admin Interface (CRUD)
1268+
Templating
1269+
Form handling
1270+
Internationalization
1271+
Session, user management, role-based permissions
1272+
Object-relational mapping (ORM)
1273+
Testing Framework
1274+
Fantastic Documentation
1275+
3) Mention the architecture of Django architecture?
1276+
1277+
Django architecture consists of
1278+
1279+
Models: It describes your database schema and your data structure
1280+
Views: It controls what a user sees, the view retrieves data from appropriate models and execute any calculation made to the data and pass it to the template
1281+
Templates: It determines how the user sees it. It describes how the data received from the views should be changed or formatted for display on the page
1282+
Controller: The Django framework and URL parsing
1283+
4) Why Django should be used for web-development?
1284+
1285+
It allows you to divide code modules into logical groups to make it flexible to change
1286+
To ease the website administration, it provides auto-generated web admin
1287+
It provides pre-packaged API for common user tasks
1288+
It gives you template system to define HTML template for your web page to avoid code duplication
1289+
It enables you to define what URL be for a given function
1290+
It enables you to separate business logic from the HTML
1291+
Everything is in python
1292+
5) Explain how you can create a project in Django?
1293+
1294+
To start a project in Django, you use command $ django-admin.py and then use the command
1295+
1296+
Project
1297+
1298+
_init_.py
1299+
1300+
manage.py
1301+
1302+
settings.py
1303+
1304+
urls.py
1305+
1306+
6) Explain how you can set up the Database in Django?
1307+
1308+
You can use the command edit mysite/setting.py , it is a normal python module with module level representing Django settings.
1309+
1310+
Django uses SQLite by default; it is easy for Django users as such it won’t require any other type of installation. In the case your database choice is different that you have to the following keys in the DATABASE ‘default’ item to match your database connection settings
1311+
1312+
Engines: you can change database by using ‘django.db.backends.sqlite3’ , ‘django.db.backeneds.mysql’, ‘django.db.backends.postgresql_psycopg2’, ‘django.db.backends.oracle’ and so on
1313+
Name: The name of your database. In the case if you are using SQLite as your database, in that case database will be a file on your computer, Name should be a full absolute path, including file name of that file.
1314+
If you are not choosing SQLite as your database then setting like Password, Host, User, etc. must be added.
1315+
1316+
7) Give an example how you can write a VIEW in Django?
1317+
1318+
Views are Django functions that take a request and return a response. To write a view in Django we take a simple example of “Guru99_home” which uses the template Guru99_home.html and uses the date-time module to tell us what the time is whenever the page is refreshed. The file we required to edit is called view.py, and it will be inside mysite/myapp/
1319+
1320+
Copy the below code into it and save the file
1321+
1322+
from datatime import datetime
1323+
1324+
from django.shortcuts import render
1325+
1326+
def home (request):
1327+
1328+
return render(request, ‘Guru99_home.html’, {‘right_now’: datetime.utcnow()})
1329+
1330+
Once you have determined the VIEW, you can uncomment this line in urls.py
1331+
1332+
# url ( r ‘^$’ , ‘mysite.myapp.views.home’ , name ‘Guru99’),
1333+
1334+
The last step will reload your web app so that the changes are noticed by the web server.
1335+
1336+
8) Explain how you can setup static files in Django?
1337+
1338+
There are three main things required to set up static files in Django
1339+
1340+
Set STATIC_ROOT in settings.py
1341+
run manage.py collectsatic
1342+
set up a Static Files entry on the PythonAnywhere web tab
1343+
9) Mention what does the Django templates consists of?
1344+
1345+
The template is a simple text file. It can create any text-based format like XML, CSV, HTML, etc. A template contains variables that get replaced with values when the template is evaluated and tags (% tag %) that controls the logic of the template.
1346+
1347+
10) Explain the use of session framework in Django?
1348+
1349+
In Django, the session framework enables you to store and retrieve arbitrary data on a per-site-visitor basis. It stores data on the server side and abstracts the receiving and sending of cookies. Session can be implemented through a piece of middleware.
1350+
1351+
11) Explain how you can use file based sessions?
1352+
1353+
To use file based session you have to set the SESSION_ENGINE settings to “django.contrib.sessions.backends.file”
1354+
1355+
12) Explain the migration in Django and how you can do in SQL?
1356+
1357+
Migration in Django is to make changes to your models like deleting a model, adding a field, etc. into your database schema. There are several commands you use to interact with migrations.
1358+
1359+
Migrate
1360+
Makemigrations
1361+
Sqlmigrate
1362+
To do the migration in SQL, you have to print the SQL statement for resetting sequences for a given app name.
1363+
1364+
django-admin.py sqlsequencreset
1365+
1366+
Use this command to generate SQL that will fix cases where a sequence is out sync with its automatically incremented field data.
1367+
1368+
13) Mention what command line can be used to load data into Django?
1369+
1370+
To load data into Django you have to use the command line Django-admin.py loaddata. The command line will searches the data and loads the contents of the named fixtures into the database.
1371+
1372+
14) Explain what does django-admin.py makemessages command is used for?
1373+
1374+
This command line executes over the entire source tree of the current directory and abstracts all the strings marked for translation. It makes a message file in the locale directory.
1375+
1376+
15) List out the inheritance styles in Django?
1377+
1378+
In Django, there is three possible inheritance styles
1379+
1380+
Abstract base classes: This style is used when you only wants parent’s class to hold information that you don’t want to type out for each child model
1381+
Multi-table Inheritance: This style is used If you are sub-classing an existing model and need each model to have its own database table
1382+
Proxy models: You can use this model, If you only want to modify the Python level behavior of the model, without changing the model’s fields
1383+
16) Mention what does the Django field class types?
1384+
1385+
Field class types determines
1386+
1387+
The database column type
1388+
The default HTML widget to avail while rendering a form field
1389+
The minimal validation requirements used in Django admin and in automatically generated forms

0 commit comments

Comments
 (0)