Django Framework Assignment
1. What is Virtualenv? Write down steps to create virtual environment.
Virtualenv is a tool in Python used to create isolated environments for different projects. It helps to
manage dependencies specific to a project without affecting other projects or system-wide
packages.
Steps to create a virtual environment:
1. Install virtualenv (if not installed): pip install virtualenv
2. Create a virtual environment: virtualenv env_name
3. Activate the virtual environment:
- On Windows: env_name\Scripts\activate
- On macOS/Linux: source env_name/bin/activate
4. Deactivate with: deactivate
2. What does MVT stand for in Django? Explain.
MVT stands for Model-View-Template, which is a design pattern used in Django to separate the
concerns of the application.
- Model: Handles the database and data-related logic.
- View: Contains the business logic and communicates with both the model and template.
- Template: Deals with the presentation layer and defines how data is presented in HTML.
Django handles much of the controller functionality itself, making development simpler.
3. Explain request-response cycle in Django.
The request-response cycle in Django works as follows:
1. A user sends a request via a browser (usually through a URL).
2. Django's URL dispatcher (urls.py) matches the URL pattern to a view.
3. The view processes the request, possibly interacts with models, and returns a response.
4. The response is passed back through Django's middleware to the user.
This cycle ensures separation of concerns and smooth flow of data and rendering.
4. What is the importance of urls.py in Django project?
The urls.py file is crucial in Django for routing. It maps URLs to views in the application. When a
user requests a specific URL, Django uses the urls.py configuration to decide which view should
handle the request.
This allows for:
- Clean and readable URLs.
- Easy management of application navigation.
- Linking different views to specific URLs without hardcoding them.