What is the best training institute for Python Internship near me?

Page 1

Refined Interview Questions on Python Web Frameworks (FLASK & DJANGO)

Address: No. 55, Ground Floor, 21st 'A' Main, Marenahalli, Industrial Area, 2nd Phase, JP Nagar, Bengaluru, Karnataka 560078 Contact: +91 9606626500 | 08043742085 www.proiba.com

Š2018 PROIBA All Rights Reserved

info@proiba.com


1) What is Python? What are the benefits of using Python? ♺ Python is a programming language with objects, modules, threads, exceptions and automatic memory management. The benefits of pythons are that it is simple and easy, portable, extensible, build-in data structure and it is an open source. 2) What is PEP 8? ♺ PEP 8 is a coding convention, a set of recommendation, about how to write your Python code more readable. 3) What is pickling and unpickling? ♺ Pickle module accepts any Python object and converts it into a string representation and dumps it into a file by using dump function, this process is called pickling. While the process of retrieving original Python objects from the stored string representation is called unpickling. 4) How Python is interpreted? ♺ Python language is an interpreted language. Python program runs directly from the source code. It converts the source code that is written by the programmer into an intermediate language, which is again translated into machine language that has to be executed. 5) How memory is managed in Python? ♺ Python memory is managed by Python private heap space. All Python objects and data structures are located in a private heap. The programmer does not have an access to this private heap and interpreter takes care of this Python private heap. ♺ The allocation of Python heap space for Python objects is done by Python memory manager. The core API gives access to some tools for the programmer to code. ♺ Python also have an inbuilt garbage collector, which recycle all the unused memory and frees the memory and makes it available to the heap space. 6) What are the tools that help to find bugs or perform static analysis? ♺ PyChecker is a static analysis tool that detects the bugs in Python source code and warns about the style and complexity of the bug. Pylint is another tool that verifies whether the module meets the coding standard. 7) What are Python decorators? ♺ A Python decorator is a specific change that we make in Python syntax to alter functions easily.

8) What is the difference between list and tuple?

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


♺ The difference between list and tuple is that list is mutable while tuple is not. Tuple can be hashed for e.g as a key for dictionaries. 9) How are arguments passed by value or by reference? ♺ Everything in Python is an object and all variables hold references to the objects. The references values are according to the functions; as a result you cannot change the value of the references. However, you can change the objects if it is mutable. 10) What is Dict and List comprehensions are? ♺ They are syntax constructions to ease the creation of a Dictionary or List based on existing iterable. 11) What are the built-in type does python provides? ♺ There are mutable and Immutable types of Pythons built in types Mutable built-in types   

List Sets Dictionaries

Immutable built-in types   

Strings Tuples Numbers

12) What is namespace in Python? ♺ In Python, every name introduced has a place where it lives and can be hooked for. This is known as namespace. It is like a box where a variable name is mapped to the object placed. Whenever the variable is searched out, this box will be searched, to get corresponding object. 13) What is lambda in Python? ♺ It is a single expression anonymous function often used as inline function. 14) Why lambda forms in python does not have statements? ♺ A lambda form in python does not have statements as it is used to make new function object and then return them at runtime. 15) What is pass in Python? ♺ Pass means, no-operation Python statement, or in other words it is a place holder in compound statement, where there should be a blank left and nothing has to be written there. 16) In Python what are iterators? ♺ In Python, iterators are used to iterate a group of elements, containers like list.

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


17) What is unittest in Python? ♺ A unit testing framework in Python is known as unittest. It supports sharing of setups, automation testing, shutdown code for tests, aggregation of tests into collections etc. 18) In Python what is slicing? ♺ A mechanism to select a range of items from sequence types like list, tuple, strings etc. is known as slicing. 19) What are generators in Python? ♺ The way of implementing iterators are known as generators. It is a normal function except that it yields expression in the function. 20) What is docstring in Python? ♺ A Python documentation string is known as docstring, it is a way of documenting Python functions, modules and classes. 21) How can you copy an object in Python? ♺ To copy an object in Python, you can try copy.copy () or copy.deepcopy() for the general case. You cannot copy all objects but most of them. 22) What is negative index in Python? ♺ Python sequences can be index in positive and negative numbers. For positive index, 0 is the first index, 1 is the second index and so forth. For negative index, (-1) is the last index and (-2) is the second last index and so forth. 23) How you can convert a number to a string? ♺ In order to convert a number into a string, use the inbuilt function str(). If you want a octal or hexadecimal representation, use the inbuilt function oct() or hex(). 24) What is the difference between Xrange and range? ♺ Xrange returns the xrange object while range returns the list, and uses the same memory and no matter what the range size is. 25) What is module and package in Python? ♺ In Python, module is the way to structure program. Each Python program file is a module, which imports other modules like objects and attributes. ♺ The folder of Python program is a package of modules. A package can have modules or subfolders. 26) Mention what are the rules for local and global variables in Python?

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


♺ Local variables: If a variable is assigned a new value anywhere within the function's body, it's assumed to be local. ♺ Global variables: Those variables that are only referenced inside a function are implicitly global. 27) How can you share global variables across modules? ♺ To share global variables across modules within a single program, create a special module. Import the config module in all modules of your application. The module will be available as a global variable across modules. 28) Explain how can you make a Python Script executable on Unix? ♺ To make a Python Script executable on Unix, you need to do two things, Script file's mode must be executable and the first line must begin with # ( #!/usr/local/bin/python) 29) Explain how to delete a file in Python? ♺ By using a command os.remove (filename) or os.unlink(filename) 30) Explain how can you generate random numbers in Python? ♺ To generate random numbers in Python, you need to import command as import random random.random() This returns a random floating point number in the range [0,1) 31) Explain how can you access a module written in Python from C? ♺ You can access a module written in Python from C by following method, Module = =PyImport_ImportModule("<modulename>"); 32) Mention the use of // operator in Python? ♺ It is a Floor Divisionoperator , which is used for dividing two operands with the result as quotient showing only digits before the decimal point. For instance, 10//5 = 2 and 10.0//5.0 = 2.0. 33) Mention five benefits of using Python?     

Python comprises of a huge standard library for most Internet platforms like Email, HTML, etc. Python does not require explicit memory management as the interpreter itself allocates the memory to new variables and free them automatically Provide easy readability due to use of square brackets Easy-to-learn for beginners Having the built-in data types saves programming time and effort from declaring variables

34) Mention the use of the split function in Python?

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


♺ The use of the split function in Python is that it breaks a string into shorter strings using the defined separator. It gives a list of all words present in the string. 35) Explain what is Flask & its benefits?  

Flask is a web micro framework for Python based on "Werkzeug, Jinja 2 and good intentions" BSD licensed. Werkzeug and jingja are two of its dependencies. Flask is part of the micro-framework. Which means it will have little to no dependencies on external libraries. It makes the framework light while there is little dependency to update and less security bugs.

36) Mention what is the difference between Django, Pyramid, and Flask?  

Flask is a "microframework" primarily build for a small application with simpler requirements. In flask, you have to use external libraries. Flask is ready to use. Pyramid are build for larger applications. It provides flexibility and lets the developer use the right tools for their project. The developer can choose the database, URL structure, templating style and more. Pyramid is heavy configurable. Like Pyramid, Django can also used for larger applications. It includes an ORM.

37) Mention what is Flask-WTF and what are their features? ♺ Flask-WTF offers simple integration with WTForms. Features include for Flask WTF are      

Integration with wtforms Secure form with csrf token Global csrf protection Internationalization integration Recaptcha supporting File upload that works with Flask Uploads

38) Explain what is the common way for the Flask script to work? ♺ The common way for the flask script to work is  

Either it should be the import path for your application Or the path to a Python file

39) Explain how you can access sessions in Flask? 

A session basically allows you to remember information from one request to another. In a flask, it uses a signed cookie so the user can look at the session contents and modify. The user can modify the session if only it has the secret key Flask.secret_key.

40) Is Flask an MVC model and if yes give an example showing MVC pattern for your application?

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


♺ Basically, Flask is a minimalistic framework which behaves same as MVC framework. So MVC is a perfect fit for Flask, and the pattern for MVC we will consider for the following example

41) Explain database connection in Python Flask? ♺ Flask supports database powered application (RDBS). Such system requires creating a schema, which requires piping the shema.sql file into a sqlite3 command. So you need to install sqlite3 command in order to create or initiate the database in Flask. Flask allows to request database in three ways   

before_request() : They are called before a request and pass no arguments after_request() : They are called after a request and pass the response that will be sent to the client teardown_request(): They are called in situation when exception is raised, and response are not guaranteed. They are called after the response been constructed. They are not allowed to modify the request, and their values are ignored.

42) You are having multiple Memcache servers running Python, in which one of the memcacher server fails, and it has your data, will it ever try to get key data from that one failed server? 

The data in the failed server won't get removed, but there is a provision for autofailure, which you can configure for multiple nodes. Fail-over can be triggered during any kind of socket or Memcached server level errors and not during normal client errors like adding an existing key, etc.

43) Explain how you can minimize the Memcached server outages in your Python Development? 

When one instance fails, several of them goes down, this will put larger load on the database server when lost data is reloaded as client make a request. To avoid this, if

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


  

your code has been written to minimize cache stampedes then it will leave a minimal impact Another way is to bring up an instance of Memcached on a new machine using the lost machines IP address Code is another option to minimize server outages as it gives you the liberty to change the Memcached server list with minimal work Setting timeout value is another option that some Memcached clients implement for Memcached server outage. When your Memcached server goes down, the client will keep trying to send a request till the time-out limit is reached

44) Explain what is Dogpile effect? How can you prevent this effect? ♺ Dogpile effect is referred to the event when cache expires, and websites are hit by the multiple requests made by the client at the same time. This effect can be prevented by using semaphore lock. In this system when value expires, first process acquires the lock and starts generating new value. 45) Explain how Memcached should not be used in your Python project?    

Memcached common misuse is to use it as a data store, and not as a cache Never use Memcached as the only source of the information you need to run your application. Data should always be available through another source as well Memcached is just a key or value store and cannot perform query over the data or iterate over the contents to extract information Memcached does not offer any form of security either in encryption or authentication

46) What are the features of Flask Python? ♺ Flask Python is one of the newest frameworks of Python and is used for designing web applications for the following features:        

Flask comes with built-in development server as well as fast debugger It also contains the integrated support required for unit testing It has the feature of restful request dispatching Comes with Jinja2 templating technique Flask supports secure cookies i.e. client-side sessions Also has the WSGI 1.0 compliant feature. It is based on Unicode. Python Flask is extensively documented.

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


47) What are the advantages of Flask Python? ♺ Flask Python comes with all the advantages of Python and some additional pros of it are: 

  

  

Flasks design is lightweight and modular. Therefore, it is easy to transform it into the web applications or framework when one needs very few extensions without weighing much. Flask is ORM-agnostic: i.e. user can plug in their favorite ORM like SqlAlchemy The basic foundation of API is very nicely shaped and made coherent. Documentation of flask is very comprehensive, filled with lots of examples and are well structured. Users can even try out some sample applications to really get the real feel of Flask. It is very easy to deploy Flask in production as Flask comes with 100% WSGI 1.0 compliant Flask can handle HTTP request easily with help of its functionalities It is highly flexible. Its configuration is even more flexible than that of Django, which gives its users plenty of solutions for every product they need.

48) What is Flask-WTF and what are their features? Explain how can you structure a large Flask application? ♺ Flask-WTF is featured to offer simple integration with WTForms. The Features include for Flask WTF are:      

Provides Integration with web forms Is very secure form as it comes with CSRF token Provides global CSRF protection Comes with internationalization integration Also features Recaptcha supporting Contains File upload that closely works with Flask Uploads

To structure a large flask application, one needs to follow these steps:   

Connect to the functions and then move them to various files, as long as users are assured that it will get imported as the applications start Then use blueprints to assign the views to various categories such as auth, backend, profile, etc. Then use the hidden Werkzeug URL map and then register functions on a central URL map.

49) How long can an identifier be in Flask Python? ♺ In Flask Python, an identifier can be of any length. Also, there are certain rules that the users must follow to name an identifier  

It should begin with a character or an underscore or from A-Z or a-z. The rest of the name of identifier can contain anything from the following: A-Z or a-z or 0-9 or _.

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


♺ Flask Python is case-sensitive so it will treat upper case and lower case letters differently. ♺ There are certain words, which are reserved in Python called keywords and they cannot be used as identifiers.Some of them are listed below: ♺ and, def, false, import, not, true, as, del, finally, in, or, try, assert, elseif, for, is, pass, while, break, else, from, lambda, print, with, class, except, global, none, raise, yield, continue, exec, if, nonlocal, return 50) What are the HTTP methods provided by Python Flask?      

HTTP methods are used to retrieve data from an URL: GET: The GET is the method that sends data to the server unencrypted. HEAD: HEAD is similar to GET, but that it has no response body. POST: The POST server does not cache the HTML form data that it sends PUT: It is the method in which the uploaded content replaces current data representations of the target resources. DELETE: This method removes the current representations of the target resource that is suggested by a URL.

51) What do you mean by template engines in Flask Python? 

When users built a website they often face the problem to keep the style of the website consistent. Sometimes the users have had to write multiple times the same text when they ever try to change the style of such websites. If the website contains only a few pages, changing its style will take the users only some time which is doable. However, if they have a lot of pages (for example the list of items sold in a mall), this task becomes monotonous and hectic. Using templates the users may set a basic layout for all their pages and provide which element needs to be changed frequently. Using this way the users can define their header once and keep it consistent in all the pages of their website, and if they need to change their header, they will only have to update it at one place. Making use a template engine will save the users a whole lot of time not only while they create their application but also when they are updating and maintaining it.

52) What are the major differences between Pyramid and Flask? 

Flask can be stated as a micro framework, which is solely built for a small application, which has simpler requirements. In flask, the users have to use external libraries. Flask is always ready to use. Pyramid, on the other hand, is built for larger application as it provides flexibility and allows the developer use the right features for their project. The developer can choose the database, templating style URL structure and more. Pyramid is therefore heavy configurable.

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


53) Explain how can one-request database connections in Flask? ♺ Flask framework allows to its users to request database in three ways. They are as follows:   

before_request()-These connections are called before making a request and no arguments are passed after_request() : These connections are called after making a request and response is passed that will be sent to the client. teardown_request(): These connections are called in a situation where an exception is raised and the response are not sure to get. They are also called after the construction of response. These are not allowed to change the request, and their values can be ignored.

54) Explain can a request context be created in Flask Python? ♺ A request profile in Flask Python can be created in two ways: On its own or auto when the application receives a request from the system Manually that is by calling app.test_request_context 55) Mention how one can enable debugging in Flask Python? ♺ There are two ways by which users can enable debugging in Flask. They are as follows:  

By setting the flag on the applications object By passing the flag as a parameter to run. If the user is enabling to debug support, the server will reload it when the code will change and the user doesn’t have to restart after each change made in the code.

56) What do you mean by the Thread-Local object in Flask Python? What are the requirements to create the database in Flask Python? ♺ Flask Python makes use of thread local objects internally so that the user doesn’t have to pass objects around from one function to another function within a request so as to stay thread safe. This approach is quite useful, but it requires a pure request context for dependency injection or while attempting to reuse code, which uses a value indulged to the requests. ♺ Flask Python supports all kinds of database-powered application like RDBS. Such systems require creating of a schema, which further requires connecting the schema.sql file to a sqlite3 command. So users need to install sqlite3 command if they want to create or start the database in Flask Python. 57) How can one-access sessions in Flask Python? State whether Flask Python is an MVC model. ♺ A session in Flask Python is a feature that allows one to remember the information from one request to another. In a flask program, it makes use of a signed cookie so that the user can look at the contents of the session and modify them. The user can also modify the sessions if and only if it has the secret key called the Flask.secret_key. Flask is a small form of Python

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


framework, which behaves the same as the MVC framework. So MVC is a perfect match for Flask. 58) What do you mean by a decorator? Name some PDB commands and their uses. ♺ A decorator is defined as a function that adds functionality to another function without changing it. It wraps the function to add some functionality to it. Some PDB commands include ♺ <b>: It adds a breakpoint ♺ <c>: It resumes the execution ♺ <s>: It debugs step by step ♺ <n>: It moves to next line ♺ <l>: It lists the source code ♺ <p>: It prints an expression 59) What do you mean by NumPy? Is it better than a list? ♺ NumPy is one of the Flask Python packages which have made its identity in the era of scientific computing. It deals with large data sizes, and also contains a powerful N dimensional array object along with a set of advanced functions. ♺ A NumPy array is much better than a list. Here are the ways:    

NumPy is more compact than list. NumPy is more convenient than the list. Numpy is more efficient than List. It is simpler to read and write items with NumPy.

60) What do you mean by pickling and unpickling? ♺ To make a portable and serialized representations of Python objects, we have the module known as pickle which accepts a Python object (basically everything in Python is an object) and then converts it into a string type, and after that uses the dump () function to dump it into a file. We term this as pickling. ♺ On the contrary, retrieving objects from the stored string forms is called as unpickling. 61) How is memory managed in Flask Python? ♺ Flask Python is a collection of private heap spaces, which holds all objects and data structures together. Programmers cannot access it. It is the task of the interpreter to manage it. But in the core API, users can access some of the tools. The Flask Python memory manager controls its allocation. Also, an inbuilt garbage collector is present which recycles all unused memory so it is made available for the heap space.

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


62) What do you understand by Django? ♺ Django is a free and open source web application framework, written in Python. Django is named after Django Reinhardt, Jazz guitarist from the 1930s to early 1950s who is one of the best guitarists of all time. Django was mainly developed to handle the intensive design of the newsroom. You can even build high-quality web applications using this. It adheres to the DRY principle and focuses completely on automating as much as possible. 63) What does Of Django Field Class types do? ♺ Following points are specified by the Django Field Class type: –   

It specifies the database column type. It also specifies the default HTML widget which is availed while we render the form field. The requirements of the minimal validation which is used in Django admin is also specified by the field class.

64) Does Django Follow Architectural pattern? ♺ Yes, Django follows Model-View-Controller (MVC) architectural pattern. 65) Clarify the architecture of Django? ♺ Django follows MVC -MVT architecture. MVT stand for Model View Template design Pattern which is little bit different from MVC (Model View Controller ) Pattern. 66) Is Django stable or not? ♺ Of course, Django is stable. Most of the companies are using it. 67) Is Django a high level or low-level framework? ♺ Django is a high-level Python’s web framework which was designed for rapid development and clean realistic design. 68) How does Django work? ♺ Django can be broken into several components:   

Models.py file: This file defines your data model by extending your single code line into full database tables and add a pre-built administration section to manage content. Urls.py file: It uses a habitual expression to confine URL patterns for processing. Views.py file: It is the main part of Django. The actual processing happens in view.

69) What is the name of the Foundation which manages Django web framework? ♺ Django web framework is managed and maintained by an independent and non-profit organization named Django Software Foundation (DSF).

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


70) Name the features available in Django web framework? ♺ Features available in Django web framework are:        

Admin Interface (CRUD) Templating Form handling Internationalization Session, user management, role-based permissions Object-relational mapping (ORM) Testing Framework Fantastic Documentation

71) What are the advantages of using Django for web development?     

Auto-generated web admin is provided by Django to make website administration easy. Pre-packaged API is also available for common user tasks. Business logic can be separated from the HTML using this framework. You can even divide the code modules into logical groups so as to make it flexible for changing. Template system is being provided so as to define HTML template for your web page to avoid code duplication.

72) What is the process of creating a project in Django? ♺ To start a project in Django, use the command $django-admin.py and then use the following command:Project _init_.py manage.py settings.py urls.py 73) Is Django a content management system (CMS)? ♺ No, Django is not a Content Management System (CMS). Instead, it is a Web framework and a programming tool that helps you in building elegant websites. 74) What does the Django templates contain? ♺ A 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 control the logic of the template.

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


75) What is the use of session framework in Django? ♺ The session framework helps you in storing and retrieving arbitrary data on a per-site visitor basis. The data is stored on the server side and abstracts the receiving and sending of cookies. We can implement sessions through a piece of middleware. 76) How can you set up static files in Django? ♺ Basically, we require three main things 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 77) How to use file based sessions? ♺ You have to set the SESSION_ENGINE settings to “django.contrib.sessions.backends.file” to use file-based session. 78) What is some typical usage of middlewares in Django? ♺ Middleware is a function that acts on or transforms a request/response before/after it passes through the view layer (e.g. adding the user object to the request) ♺ Some usage of middlewares in Django is:    

It can be used for Session management, User authentication can be done with the help of this. It helps in Cross-site request forgery protection Content Gzipping, etc.

79) 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: 80) 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. 81) What are signals in Django? ♺ Signal are inbuilt utility in Django. They allow to execute some piece of code based on some action or event is occurred in framework something like a new user register, on delete of a record. ♺ Below is the list of some inbuilt signal in Django. 

pre_save and post_save.

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


  

pre_delete and post_delete pre_request and post_request pre_request and post_request

82) Is Django free? ♺ Yes, Django is free open source web framework for Python 83) Django is based on which design pattern. ♺ Django closely follows the MVC (Model View Controller) design pattern, however, it does use its own logic in the implementation. Because the “C” is handled by the framework itself and most of the excitement in Django happens in models, templates, and views, Django is often referred to as an MTV framework. In the MTV development pattern: ♺ M stands for “Model,” the data access layer. This layer contains anything and everything about the data: how to access it, how to validate it, which behaviors it has, and the relationships between the data. ♺ T stands for “Template,” the presentation layer. This layer contains presentation-related decisions: how something should be displayed on a Web page or other type of document. ♺ V stands for “View,” the business logic layer. This layer contains the logic that accesses the model and defers to the appropriate template(s). You can think of it as the bridge between models and templates. Visit for more https://djangobook.com/model-view-controller-design-pattern/ 83) When and who create Django? ♺ According to https://en.wikipedia.org/wiki/Django_(web_framework), Django was created in the fall of 2003, when the web programmers at the Lawrence Journal-World newspaper, Adrian Holovaty and Simon Willison, began using Python to build applications. It was released publicly under a BSD license in July 2005. The framework was named after guitarist Django Reinhardt. 84) List server requirement to install Django Framework. ♺ As Django is Python Framework, in order to install Django Python is required.Django comes with an inbuilt lightweight web server that you can use for the testing purpose.If you are using Django on production Apache with mod_wsgi is required. 85) List the database backends supported by Django Framework? ♺ Django officially supports four database backends, they are    

PostgreSQL MySQL SQLite Oracle &

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


In addition to these, you can also use following 3rd parties     

SAP SQL Anywhere IBM DB2 Microsoft SQL Server Firebird ODBC

86) What is recommended way to install Django? ♺ Installing using pip is the recommended way to install Django Framework. Below are the steps to install official release of Django with pip ♺ Install pip. Configure virtualenv and virtualenvwrapper ♺ Once virtual environment is created and activated, enter the command pip install Django to install Django 87) How to install the development version of Django ♺ Follow the below steps to Install the development version of Django Framework.     

Check out Django’s main development branch $ git clone https://github.com/django/django.git Make sure that the Python interpreter can load Django’s code. The most convenient way to do this is to use virtualenv, virtualenvwrapper, and pip. After setting up and activating the virtualenv, run the following command: $ pip install -e django/

Read More: https://docs.djangoproject.com/en/2.0/topics/install/ 88) Where are Django migrations stored? ♺ You can think Django Migrations as version control system for your database/Model. It keeps track of changes done in your application Models/Table like adding a field, deleting a model, etc. Migrations in Django are stored as an on-disk format, referred to here as “migration files”. These files are actually just normal Python files with an agreed-upon object layout, written in a declarative style. A basic migration file looks like this:

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


Further Reading https://docs.djangoproject.com/en/2.0/topics/migrations/ 89) How a request is processed in Django? ♺ In Django whenever a request is made by a user, it goes through the following steps: 

  

Django determines the root URLconf module to use. Ordinarily, this is the value of the ROOT_URLCONF setting, but if the incoming HttpRequest object has a urlconf attribute (set by middleware), its value will be used in place of the ROOT_URLCONF setting. Django loads that Python module and looks for the variable urlpatterns. This should be a Python list of django.urls.path() and/or django.urls.re_path() instances. Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL. Once one of the URL patterns matches, Django imports and calls the given view, which is a simple Python function (or a class-based view). The view gets passed the following arguments:

An instance of HttpRequest.  

If the matched URL pattern returned no named groups, then the matches from the regular expression are provided as positional arguments. The keyword arguments are made up of any named parts matched by the path expression, overridden by any arguments specified in the optional kwargs argument to django.urls.path() or django.urls.re_path(). If no URL pattern matches, or if an exception is raised during any point in this process, Django invokes an appropriate error-handling view.

90) When to use the iterator in Django ORM? ♺ Iterators are used for traversing an object in Python which implements iterator protocol. It consists of two methods __iter__() and next().  

In Django, a good use of iterator is when you are processing results that take up a large amount of available memory (lots of small objects or fewer large objects). For more clarification please read when to use and when to not use iterator() in the Python Django ORM

https://stackoverflow.com/questions/12681653/when-to-use-or-not-use-iterator-in-thedjango-orm 91) When QuerySets are evaluated in Django? ♺ In Django, a QuerySet can be evaluated in Iteration, Slicing, Pickling/Caching, repr(),len(), list() and bool().

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


92) How to check installed version of Django? ♺ By running below command on Terminal.You can check installed version of Django Framework. py -m django --version 93) How to set/unset session in Django? ♺ Setting Session in Django request.session['key'] = 'value' Unset Session in Django del request.session['key'] 94) What is a context in Django? ♺ In Django Context is a dictionary with variable names in the form of key and value like {varible1: 101, varible2: 102},when we pass this context to the template render method, {{ varible1 }} would be replaced with 101 and {{ varible2 }} with 102 in your template. 95) Explain mixins in Django. ♺ A mixin is a special kind of multiple inheritances in Python. There are two main situations where mixins are used:  

You want to provide a lot of optional features for a class. You want to use one particular feature in a lot of different classes.

Read More they-useful

https://stackoverflow.com/questions/533631/what-is-a-mixin-and-why-are-

96) How to get current page URI in Django template. ♺ You can use {{ request.path }} and {{ request.get_full_path }} to get current page URI in Django template 97) List some popular websites built on Django framework? ♺ Following are the list of top 10 websites built on Django framework.          

Instagram Disqus Bitbucket Mozilla Firefox Pinterest NASA Onion The Washington Post Eventbrite Mahalo

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


98) How to create an Constant in Django. ♺ To create a constant in Django. Open your settings.py file and add a variable like MY_CONST = “MY_VALUE”. ♺ To use this constant in your views simply import setting like “Import settings in views.py” and use it as settings.MY_CONST

'Kick-start your career in IT as Business Analyst, Project Manager, SAP Technologist, Python Development, Data Science, Artificial Intelligence, Web Developer, Software Tester, On job support with Proiba's fully accredited classes, Educators and Certificates. Study with experienced Professionals in an intimate, supportive and engaged learning environment.'

www.proiba.com

| ©2018 PROIBA All Rights Reserved | info@proiba.com | +91 9606626500


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.