🚀 Supercharge your YouTube channel's growth with AI.
Try YTGrowAI FreeTop 100 Python Web Development MCQs

Python is widely used in web development due to its simplicity and powerful frameworks like Django and Flask. Django offers built-in features for security and admin management, and Flask is ideal for lightweight, flexible applications. Python also supports REST API development and efficient database handling, making it suitable for both startups and large-scale systems.
This 100 Python Web Development MCQ set covers key backend concepts, including HTTP fundamentals, Django (MVT, ORM), Flask (routing, sessions), API development, and security practices like CSRF protection.
100 Python Web Development MCQs with Answers
Q1. Which protocol is primarily used by web browsers to communicate with servers for retrieving web pages?
A. FTP
B. HTTP
C. SMTP
D. TCP
Show Answer
Answer: B
HTTP (HyperText Transfer Protocol) is the foundation of data communication for the World Wide Web.
Q2. In the Model-View-Template (MVT) architecture used by Django, which component handles the business logic and database interaction?
A. View
B. Model
C. Template
D. Controller
Show Answer
Answer: B
The Model acts as the data access layer and handles the database structure and business logic.
Q3. Which Python web framework is known for being a “microframework” and does not require specific tools or libraries by default?
A. Django
B. Flask
C. Pyramid
D. TurboGears
Show Answer
Answer: B
Flask is a lightweight WSGI web application framework that does not require database abstraction or form validation by default.
Q4. What is the correct HTTP status code range that indicates a successful request?
A. 100-199
B. 200-299
C. 300-399
D. 400-499
Show Answer
Answer: B
HTTP status codes in the 200-299 range signify that the client’s request was successfully received and processed.
Q5. Which method in the Python `requests` library is used to send a GET request to a specified URL?
A. requests.get()
B. requests.post()
C. requests.fetch()
D. requests.retrieve()
Show Answer
Answer: A
The `requests.get()` method sends a GET request to the specified URL to retrieve data.
Q6. In Django, which file is primarily responsible for mapping URLs to specific view functions?
A. models.py
B. views.py
C. urls.py
D. settings.py
Show Answer
Answer: C
The `urls.py` file contains the URLconf which maps URL patterns to view functions in Django.
Q7. Which HTTP method is specifically designed for submitting form data or uploading files to a server?
A. GET
B. POST
C. PUT
D. DELETE
Show Answer
Answer: B
The POST method is used to send data to the server to create or update a resource, often used with HTML forms.
Q8. What is the primary function of the WSGI (Web Server Gateway Interface) in Python web development?
A. To create database models
B. To handle URL routing
C. To act as a bridge between web servers and Python applications
D. To compile Python code
Show Answer
Answer: C
WSGI acts as a standard interface between web servers (like Nginx/Apache) and Python web applications (like Django/Flask).
Q9. In Flask, which object is used to store session data for a specific user?
A. request
B. session
C. g
D. config
Show Answer
Answer: B
The `session` object in Flask allows you to store information specific to a user from one request to the next.
Q10. Which specific HTTP status code indicates that the requested resource could not be found on the server?
A. 200 OK
B. 301 Moved Permanently
C. 404 Not Found
D. 500 Internal Server Error
Show Answer
Answer: C
HTTP status code 404 is the standard response indicating that the server cannot find the requested resource.
Q11. In Django, what is the primary purpose of the `manage.py` file?
A. To define database models
B. To handle URL configurations
C. To execute administrative commands for the project
D. To render HTML templates
Show Answer
Answer: C
`manage.py` is a command-line utility that lets you interact with the Django project in various ways, such as running the server or creating migrations.
Q12. Which decorator is commonly used in Flask to associate a URL route with a specific function?
A. @app.route()
B. @app.url()
C. @flask.connect()
D. @route.path()
Show Answer
Answer: A
The `@app.route()` decorator is used in Flask to bind a function to a specific URL route.
Q13. What does JSON stand for in the context of web APIs?
A. Java Standard Object Notation
B. JavaScript Object Notation
C. Java Serialized Object Naming
D. JavaScript Online Notation
Show Answer
Answer: B
JSON stands for JavaScript Object Notation and is a lightweight format for storing and transporting data.
Q14. Which Django component is responsible for mapping Python objects to database tables?
A. Template Engine
B. ORM (Object-Relational Mapper)
C. URL Dispatcher
D. View Controller
Show Answer
Answer: B
Django’s ORM allows developers to interact with the database using Python objects instead of writing raw SQL queries.
Q15. Which HTTP request method is idempotent, meaning making the same request multiple times produces the same result?
A. POST
B. PATCH
C. GET
D. CONNECT
Show Answer
Answer: C
GET is an idempotent method as it only retrieves data without changing the state of the server.
Q16. In Django migrations, which command is used to create new migration files based on changes detected in models?
A. python manage.py migrate
B. python manage.py makemigrations
C. python manage.py create_migration
D. python manage.py update_db
Show Answer
Answer: B
`makemigrations` scans the models and creates new migration files that describe the database schema changes.
Q17. Which Flask object is used to access incoming request data like form values or JSON payloads?
A. flask.config
B. flask.request
C. flask.session
D. flask.input
Show Answer
Answer: B
The `request` object contains all the data sent by the client, including form data, query parameters, and files.
Q18. What is the default port number used when running a Django development server?
A. 80
B. 443
C. 8000
D. 5000
Show Answer
Answer: C
Django’s development server typically runs on port 8000 by default, while Flask defaults to port 5000.
Q19. Which security feature in Django automatically protects against Cross-Site Request Forgery (CSRF) attacks?
A. CSRF Token
B. SSL Certificate
C. JSON Web Token
D. Middleware Authentication
Show Answer
Answer: A
Django provides a CSRF middleware that adds a unique token to forms to prevent malicious sites from submitting requests on behalf of a user.
Q20. Which of the following is a valid way to run a Flask application named `app.py` from the terminal?
A. flask run
B. python app.py
C. flask start
D. Both A and B
Show Answer
Answer: D
You can run a Flask app using `flask run` (if FLASK_APP is set) or by calling `app.run()` inside a Python script executed via `python app.py`.
Q21. In the context of REST APIs, what does the acronym REST stand for?
A. Representative State Transfer
B. Representational State Transfer
C. Remote Execution State Transfer
D. Reliable Standard Transfer
Show Answer
Answer: B
REST stands for Representational State Transfer, an architectural style for designing networked applications.
Q22. Which Django field type is best suited for storing a large amount of text, such as the content of a blog post?
A. CharField
B. TextField
C. StringField
D. LongField
Show Answer
Answer: B
`TextField` is used for long text strings, while `CharField` is generally used for shorter strings like titles or names.
Q23. Which Python library is widely used for parsing HTML and XML documents, often utilized in web scraping?
A. Scrapy
B. Beautiful Soup
C. Requests
D. Selenium
Show Answer
Answer: B
Beautiful Soup is a library designed for parsing HTML and XML structures to extract data from web pages.
Q24. Which HTTP status code indicates that the server encountered an unexpected error?
A. 400 Bad Request
B. 403 Forbidden
C. 404 Not Found
D. 500 Internal Server Error
Show Answer
Answer: D
Status code 500 signifies that the server encountered an error that prevented it from fulfilling the request.
Q25. In Django, what is the purpose of the `admin` interface?
A. To manage user authentication
B. To automatically generate a CRUD interface for registered models
C. To handle static files
D. To configure URL routes
Show Answer
Answer: B
Django’s admin site provides a ready-to-use interface for administrators to create, read, update, and delete model content.
Q26. How do you define a dynamic URL segment in Flask, such as capturing a username in `/user/`?
A. @app.route(‘/user/username’)
B. @app.route(‘/user/<username>
C. @app.route(‘/user/$username’)
D. @app.route(‘/user/{username}’)
Show Answer
Answer: B
Flask uses angle brackets `< >` to define variable parts in a URL which are passed as arguments to the view function.
Q27. Which command is used to start a new Django application named “blog” within an existing project?
A. django-admin startapp blog
B. python manage.py startapp blog
C. django-admin createapp blog
D. python manage.py createapp blog
Show Answer
Answer: B
Within a project, `python manage.py startapp
Q28. Which HTTP header is used to indicate the media type of the resource sent to the client?
A. Content-Type
B. Authorization
C. Accept
D. User-Agent
Show Answer
Answer: A
The `Content-Type` header tells the client what the content type of the returned data actually is (e.g., application/json, text/html).
Q29. What is the primary role of a template engine in Python web frameworks?
A. To compile Python code
B. To generate dynamic HTML pages by combining static data with dynamic data
C. To manage database connections
D. To handle HTTP requests
Show Answer
Answer: B
Template engines allow developers to embed dynamic logic (like variables and loops) directly into HTML files.
Q30. Which Django model field is used to create a one-to-many relationship?
A. OneToOneField
B. ManyToManyField
C. ForeignKey
D. ManyToOneField
Show Answer
Answer: C
A `ForeignKey` field is used to define a many-to-one relationship in Django models.
Q31. In Flask, what does the `debug=True` parameter do when running the application?
A. It runs the app on the public IP.
B. It disables logging.
C. It enables the debugger and auto-reloader.
D. It compiles the app to bytecode.
Show Answer
Answer: C
Setting `debug=True` enables the interactive debugger and auto-reloading, which is useful during development but should be turned off in production.
Q32. Which Python web framework strictly follows the “Batteries Included” philosophy?
A. Flask
B. Django
C. Bottle
D. CherryPy
Show Answer
Answer: B
Django follows the “Batteries Included” philosophy, providing built-in tools for admin, ORM, authentication, and more.
Q33. Which status code indicates that a resource has been permanently moved to a new URL?
A. 301 Moved Permanently
B. 302 Found
C. 307 Temporary Redirect
D. 401 Unauthorized
Show Answer
Answer: A
Status code 301 is used for permanent redirection, meaning the client should update its links to the new URL.
Q34. In Django, which function is used inside a view to render an HTML template with a context dictionary?
A. render()
B. response()
C. template()
D. load()
Show Answer
Answer: A
The `render()` function combines a template with a context dictionary and returns an HttpResponse object.
Q35. What is the primary purpose of using a virtual environment in Python web development?
A. To speed up the application.
B. To isolate project dependencies and versions.
C. To automatically deploy code.
D. To increase the server memory.
Show Answer
Answer: B
Virtual environments create isolated spaces to prevent conflicts between project dependencies.
Q36. Which Django file is responsible for registering models so they appear in the admin interface?
A. models.py
B. admin.py
C. views.py
D. settings.py
Show Answer
Answer: B
The `admin.py` file is where developers register models to make them accessible in the Django admin panel.
Q37. Which HTTP method is used to update an existing resource on a server?
A. POST
B. GET
C. PUT
D. COPY
Show Answer
Answer: C
The PUT method is used to update an existing resource or create a new resource at a known URL.
Q38. In Flask, how do you access the query string parameter `id` from a URL like `/item?id=123`?
A. request.form[‘id’]
B. request.args.get(‘id’)
C. request.data[‘id’]
D. request.query[‘id’]
Show Answer
Answer: B
`request.args` is a dictionary containing the parsed query string parameters in Flask.
Q39. What is the name of the default templating language used by Django?
A. Jinja2
B. Mako
C. Django Template Language (DTL)
D. Genshi
Show Answer
Answer: C
Django has its own built-in template language called Django Template Language (DTL), though it can support others like Jinja2.
Q40. Which HTTP status code indicates that a user is not authenticated to access a resource?
A. 403 Forbidden
B. 401 Unauthorized
C. 404 Not Found
D. 500 Server Error
Show Answer
Answer: B
Status code 401 indicates that the request lacks valid authentication credentials for the target resource.
Q41. In Django, what is the purpose of the `urlpatterns` list?
A. To define database constraints
B. To map URL patterns to view functions
C. To list installed applications
D. To store static file paths
Show Answer
Answer: B
The `urlpatterns` list in `urls.py` defines the routing logic by connecting URL strings to Python functions.
Q42. Which Python library is essential for creating a REST API in Flask?
A. Flask-RESTful
B. Flask-API
C. Django REST Framework
D. Flask-Script
Show Answer
Answer: A
Flask-RESTful is an extension for Flask that adds support for quickly building REST APIs.
Q43. In the context of database management in Django, what does the `makemigrations` command actually do?
A. It applies changes to the database.
B. It reads the models file and creates migration files describing changes.
C. It deletes the database.
D. It creates a superuser account.
Show Answer
Answer: B
`makemigrations` inspects the models and generates new migration files that describe the schema changes, but does not apply them.
Q44. Which tag in Django Template Language is used to load static files into a template?
A. {% load static %}
B. {% import static %}
C. {% include static %}
D. {% static_load %}
Show Answer
Answer: A
The `{% load static %}` tag imports the static module, allowing the use of `{% static ‘path’ %}` to reference files.
Q45. Which decorator in Django is used to restrict access to a view only for logged-in users?
A. @login_required
B. @authenticate
C. @restrict_user
D. @permission_required
Show Answer
Answer: A
The `@login_required` decorator checks if a user is authenticated before allowing access to the view.
Q46. What is the standard method to return a JSON response in a Flask view function?
A. return dict(data=value)
B. return jsonify(data=value)
C. return json(data=value)
D. return Response.json(data=value)
Show Answer
Answer: B
Flask provides the `jsonify()` function to convert Python dictionaries into proper JSON responses with the correct Content-Type header.
Q47. Which Python web server gateway interface is commonly used to serve Django applications in production?
A. python server.py
B. manage.py runserver
C. Gunicorn
D. WampServer
Show Answer
Answer: C
Gunicorn (Green Unicorn) is a Python WSGI HTTP server for UNIX, widely used to deploy Django and Flask apps.
Q48. What is the correct syntax for a simple for loop in the Django Template Language?
A. {% for item in items %} … {% endfor %}
B. {{ for item in items }} … {{ endfor }}
C. [for item in items] … [endfor]
D. {% loop item in items %} … {% endloop %}
Show Answer
Answer: A
Django templates use `{% %}` for tags and logic blocks like loops and conditionals.
Q49. Which HTTP method is used to remove a resource from a server?
A. REMOVE
B. DELETE
C. ERASE
D. POST
Show Answer
Answer: B
The DELETE method requests that the server delete the resource identified by the Request-URL.
Q50. In Django, what is the purpose of the `settings.py` file?
A. To define URL routes.
B. To contain all the configuration for the Django project.
C. To write view logic.
D. To define HTML templates.
Show Answer
Answer: B
`settings.py` contains configuration such as database settings, installed apps, middleware, and static file locations.
Q51. Which Flask feature allows you to organize an application into modular components?
A. Blueprints
B. Modules
C. Packages
D. Components
Show Answer
Answer: A
Blueprints in Flask allow developers to group routes, templates, and static files into reusable modules.
Q52. What does the term “Middleware” refer to in Django?
A. The database interface.
B. A framework of hooks into the request/response processing.
C. The HTML templating engine.
D. The URL routing mechanism.
Show Answer
Answer: B
Middleware is a lightweight plugin that processes request and response objects globally before they reach the view or the user.
Q53. Which command is used to create a superuser in Django?
A. python manage.py createuser
B. python manage.py createsuperuser
C. python manage.py admin
D. django-admin createsuperuser
Show Answer
Answer: B
`python manage.py createsuperuser` creates a user account with administrative privileges.
Q54. In Django models, which field option is used to make a field unique?
A. unique=True
B. primary_key=True
C. distinct=True
D. null=False
Show Answer
Answer: A
The `unique=True` option ensures that no two records have the same value for that specific field.
Q55. Which response object in Flask is returned by default from a view function?
A. JsonResponse
B. HttpResponse
C. Response
D. FlaskResponse
Show Answer
Answer: C
Flask automatically converts the return value from a view function into a response object, but the base class is `Response`.
Q56. What is Cross-Origin Resource Sharing (CORS)?
A. A database optimization technique.
B. A browser security mechanism that controls access to resources on a different origin.
C. A Python templating standard.
D. A method for routing URLs.
Show Answer
Answer: B
CORS is a browser security feature that restricts web pages from making requests to a different domain than the one serving the page.
Q57. Which Django method is used to retrieve a single record from the database, raising an error if it does not exist?
A. Model.get()
B. Model.objects.get()
C. Model.filter()
D. Model.all()
Show Answer
Answer: B
`Model.objects.get()` retrieves a single object matching the given lookup parameters, raising `DoesNotExist` if not found.
Q58. Which Python decorator is used in Flask to handle exceptions like 404 errors globally?
A. @app.errorhandler
B. @app.exception
C. @app.catch
D. @error.route
Show Answer
Answer: A
The `@app.errorhandler` decorator registers a function to handle a specific error code or exception.
Q59. What is the purpose of the `requirements.txt` file in a Python web project?
A. To list the database requirements.
B. To document the Python version.
C. To list the project dependencies and their versions.
D. To store environment variables.
Show Answer
Answer: C
`requirements.txt` lists the pip packages required to run the project, allowing easy installation via `pip install -r requirements.txt`.
Q60. In Django, which class is used to create a form based on a model?
A. Form
B. ModelForm
C. ModelFormSet
D. FormModel
Show Answer
Answer: B
`ModelForm` is a helper class that allows you to create a Django Form directly from a Django model.
Q61. Which HTTP verb is idempotent but used for partial updates of a resource?
A. PUT
B. PATCH
C. POST
D. GET
Show Answer
Answer: B
PATCH is used for partial modifications to a resource, whereas PUT replaces the entire resource.
Q62. Which function in the `requests` library checks if the HTTP request was successful?
A. response.ok
B. response.status
C. response.success()
D. response.check()
Show Answer
Answer: A
The `response.ok` attribute returns True if the status code is less than 400, indicating a successful request.
Q63. In Django templates, how do you properly display a variable named `title`?
A. {{ title }}
B. {% title %}
C. #{ title }
D. [[ title ]]
Show Answer
Answer: A
Django uses double curly braces `{{ }}` to output the value of a variable in a template.
Q64. What is the main difference between `render_template` and `redirect` in Flask?
A. render_template sends HTML, redirect sends a URL.
B. render_template sends JSON, redirect sends HTML.
C. render_template is for GET, redirect is for POST.
D. There is no difference.
Show Answer
Answer: A
`render_template` renders a template file into HTML, while `redirect` tells the browser to navigate to a different URL.
Q65. Which Django utility function is used to prevent SQL injection attacks by separating SQL logic from data?
A. django.db.connection
B. QuerySets
C. raw()
D. cursor()
Show Answer
Answer: B
Django’s QuerySets automatically escape query parameters, protecting against SQL injection.
Q66. Which HTTP header is used by the client to send authentication credentials to the server?
A. WWW-Authenticate
B. Authorization
C. Auth-Token
D. Credentials
Show Answer
Answer: B
The `Authorization` header contains the credentials (like tokens or Basic Auth) to authenticate a user agent with a server.
Q67. In Django, what does `auto_now=True` do in a DateTime field?
A. Sets the time manually.
B. Updates the timestamp every time the object is saved.
C. Sets the time only when the object is created.
D. Prevents the field from being edited.
Show Answer
Answer: B
The `auto_now=True` option updates the field to the current timestamp every time the model object is saved.
Q68. Which Python extension is commonly used for database migrations in Flask applications?
A. Flask-Migrate
B. Flask-DB
C. Flask-SQL
D. Flask-Alembic
Show Answer
Answer: A
Flask-Migrate is an extension that handles SQLAlchemy database migrations for Flask applications using Alembic.
Q69. What is the correct command to install the Django framework using pip?
A. pip install django-framework
B. pip install django
C. pip install Django
D. Both B and C
Show Answer
Answer: D
Pip is case-insensitive for package names, so `pip install django` and `pip install Django` both work.
Q70. Which status code indicates that a request has been accepted for processing but not yet completed?
A. 200 OK
B. 201 Created
C. 202 Accepted
D. 204 No Content
Show Answer
Answer: C
HTTP 202 Accepted is typically returned for asynchronous processing where the result is not immediately available.
Q71. In Django, what is the purpose of the `include()` function in `urls.py`?
A. To import Python modules.
B. To include another URLconf module, allowing project-level routing to app-level routing.
C. To include static files.
D. To include middleware.
Show Answer
Answer: B
`include()` allows you to reference another URLconf, making it easier to plug in apps and keep URL routing modular.
Q72. Which HTML element is used to trigger a CSRF token check in a Django form?
A. {% csrf_token %}
B. {{ csrf_token }}
C. #csrf_token
Show Answer
Answer: A
The `{% csrf_token %}` tag outputs a hidden input field containing the CSRF token required by Django middleware.
Q73. What is the default session type in Flask?
A. Server-side filesystem
B. Client-side cookie
C. Database
D. Redis
Show Answer
Answer: B
By default, Flask uses client-side cookie-based sessions where the session data is signed and stored in the browser cookie.
Q74. Which Python library is used for object-relational mapping in Flask?
A. SQLAlchemy
B. Peewee
C. Django ORM
D. Both A and B
Show Answer
Answer: D
Flask can use various ORMs, but SQLAlchemy (via Flask-SQLAlchemy) and Peewee are common choices.
Q75. What is the purpose of the `static` folder in a Django or Flask project?
A. To store Python source code.
B. To store database files.
C. To store CSS, JavaScript, and image files.
D. To store HTML templates.
Show Answer
Answer: C
The `static` directory is conventionally used to store static assets like stylesheets, scripts, and images.
Q76. Which status code indicates that the server understands the request but refuses to authorize it?
A. 401 Unauthorized
B. 403 Forbidden
C. 404 Not Found
D. 400 Bad Request
Show Answer
Answer: B
403 Forbidden means the user might be authenticated but does not have permission to access the specific resource.
Q77. In Django, what does the `@property` decorator do inside a model class?
A. Defines a database column.
B. Allows a method to be accessed like an attribute.
C. Marks a field as read-only in the database.
D. Creates a URL route.
Show Answer
Answer: B
The `@property` decorator turns a method into a read-only property, allowing access via dot notation without parentheses.
Q78. Which Flask configuration variable is essential for securing session cookies?
A. SECRET_KEY
B. SESSION_KEY
C. SECURITY_KEY
D. PRIVATE_KEY
Show Answer
Answer: A
The `SECRET_KEY` is used to sign session cookies and other security-related features to prevent tampering.
Q79. What is the primary advantage of using an asynchronous framework like FastAPI over synchronous frameworks like Flask?
A. Better syntax for HTML.
B. Ability to handle high concurrency and I/O-bound tasks more efficiently.
C. Built-in database support.
D. Easier routing logic.
Show Answer
Answer: B
Asynchronous frameworks can handle many connections at once without blocking, making them ideal for high-performance APIs.
Q80. Which Django method filters records based on multiple conditions joined by OR logic?
A. Model.objects.filter()
B. Model.objects.get()
C. Model.objects.filter(Q(condition1) | Q(condition2))
D. Model.objects.or_filter()
Show Answer
Answer: C
Django’s `Q` objects allow for complex lookups, including OR conditions, using the bitwise OR operator `|`.
Q81. Which file is commonly used to deploy a Python web application to Heroku to specify dependencies?
A. Procfile
B. requirements.txt
C. runtime.txt
D. setup.py
Show Answer
Answer: B
Heroku uses `requirements.txt` to automatically detect and install Python dependencies during deployment.
Q82. In web development, what does XSS stand for?
A. Cross-Site Scripting
B. Cross-Site Security
C. Client-Side Scripting
D. Cross-Server Scripting
Show Answer
Answer: A
XSS (Cross-Site Scripting) is a vulnerability where attackers inject malicious scripts into web pages viewed by other users.
Q83. Which method in Django QuerySets returns the number of records matching the query?
A. len()
B. count()
C. size()
D. total()
Show Answer
Answer: B
The `count()` method performs a `SELECT COUNT(*)` at the database level, which is more efficient than `len()`.
Q84. Which Python library provides a high-level API for Selenium web driver automation?
A. selenium
B. requests
C. scrapy
D. webdriver_manager
Show Answer
Answer: A
The `selenium` package allows Python scripts to control web browsers for testing and scraping purposes.
Q85. What is the file extension for the Django HTML template files?
A. .dhtml
B. .dtl
C. .html
D. .django
Show Answer
Answer: C
Django templates are standard HTML files (`.html`) that contain the Django Template Language syntax embedded within them.
Q86. In Flask, where is the `templates` folder located by default?
A. Inside the `static` folder.
B. Inside the application root folder.
C. Inside the `instance` folder.
D. Inside the Python site-packages.
Show Answer
Answer: B
By default, Flask looks for the `templates` folder in the root directory of the application module.
Q87. Which HTTP status code indicates that a new resource was successfully created?
A. 200 OK
B. 201 Created
C. 202 Accepted
D. 204 No Content
Show Answer
Answer: B
HTTP 201 Created is the standard response for a successful POST request that results in the creation of a resource.
Q88. What is the role of a View in Django?
A. To define the database schema.
B. To accept an HTTP request and return an HTTP response.
C. To store static files.
D. To configure the server settings.
Show Answer
Answer: B
A Django view is a Python function that takes a web request and returns a web response, acting as the logic layer.
Q89. Which Django signal is sent after a model’s `save()` method is called?
A. pre_save
B. post_save
C. pre_delete
D. post_init
Show Answer
Answer: B
The `post_save` signal is triggered at the end of the save process, allowing custom logic after a record is updated or created.
Q90. Which Python package is specifically designed for creating JWT (JSON Web Tokens) in web applications?
A. PyJWT
B. requests-jwt
C. django-jwt
D. authlib
Show Answer
Answer: A
PyJWT is a Python library used to encode and decode JSON Web Tokens for authentication.
Q91. What is the purpose of the `url_for` function in Flask?
A. To check if a URL is valid.
B. To generate a URL to a specific function dynamically.
C. To redirect to an external website.
D. To parse URL parameters.
Show Answer
Answer: B
`url_for` generates a URL to the endpoint associated with a specific view function, helping avoid hardcoding URLs.
Q92. In Django, what is `QuerySet`?
A. A list of SQL commands.
B. A collection of objects from the database.
C. A template tag.
D. A configuration setting.
Show Answer
Answer: B
A QuerySet represents a collection of objects from your database and allows you to read, filter, and order data.
Q93. Which HTTP request header indicates the URL from which the request originated?
A. Origin
B. Referer
C. Host
D. Source
Show Answer
Answer: B
The `Referer` header contains the address of the previous web page from which a link to the currently requested page was followed.
Q94. What is the function of the `select_related` method in Django QuerySets?
A. To select specific fields.
B. To perform a SQL join and reduce database queries for foreign key relationships.
C. To select related many-to-many fields.
D. To filter related objects.
Show Answer
Answer: B
`select_related` returns a QuerySet that “follows” foreign-key relationships, selecting additional related-object data in a single query.
Q95. Which tool is commonly used to serve Python web applications alongside Nginx or Apache?
A. uWSGI
B. Tomcat
C. Node.js
D. IIS
Show Answer
Answer: A
uWSGI is a software application that aims to develop a full stack for building hosting services, often used as a WSGI server.
Q96. How can you validate a form in a Django view?
A. form.check()
B. form.is_valid()
C. form.validate()
D. form.verify()
Show Answer
Answer: B
The `is_valid()` method runs validation logic on the form data and returns True if the data is valid.
Q97. Which status code indicates that the server is unavailable due to maintenance or overload?
A. 500 Internal Server Error
B. 502 Bad Gateway
C. 503 Service Unavailable
D. 504 Gateway Timeout
Show Answer
Answer: C
HTTP 503 Service Unavailable indicates that the server is not ready to handle the request, often due to temporary maintenance.
Q98. In Flask, what is the purpose of the `url_map` attribute?
A. To store static file paths.
B. To store the mapping of URLs to view functions.
C. To store configuration variables.
D. To store session data.
Show Answer
Answer: B
The `url_map` on the Flask app object contains the routing information linking URL rules to endpoints.
Q99. Which decorator in Django is used to require specific HTTP methods for a view?
A. @require_http_methods
B. @http_method
C. @allowed_methods
D. @restrict_methods
Show Answer
Answer: A
The `@require_http_methods` decorator restricts a view to accept only specified HTTP methods (e.g., GET, POST).
Q100. What is the primary characteristic of a RESTful API?
A. It uses XML exclusively.
B. It is stateless, meaning each request contains all information needed to process it.
C. It requires a specific frontend framework.
D. It maintains a persistent connection to the server.
Show Answer
Answer: B
Statelessness is a core constraint of REST, ensuring that the server does not store any context about the client session between requests.
Conclusion
That’s it for this 100 Python Web Development MCQs question bank! I know, I know, it looks big and hard to remember everything, but you don’t need to memorise it all. Just bookmark this page and go through it twice a week. With consistent revision, you’ll naturally start remembering the concepts and understanding them deeply within a few weeks.
Now, if you want to go further in Python and strengthen your interview preparation, check out these curated resources:
- 100 Python Interview Questions
- In case you are into Machine Learning check out Machine Learning Interview Questions
You can also explore questions focused on specific libraries and frameworks:
- Top 50 Pandas Interview Questions
- Top 50 Flask Interview Questions
- Top 50 Django Interview Questions
These resources will help you understand and prepare for real-world Python development and interviews.

