PYTHON for Web Flask Django MCQs

  1. Which library is a micro web framework in Python?
    a) Flask
    b) Django
    c) Pyramid
    d) Bottle
    View Answer

    Correct answer: A — Flask

  2. What will be printed?
    1 python
    2 from flask import Flask
    3 app = Flask(__name__)
    4 print(app.name)
    a) main
    b) Flask
    c) Error
    d) None
    View Answer

    Correct answer: A — main

  3. Which decorator is used to define a route in Flask?
    a) @app.route()
    b) @app.url()
    c) @app.path()
    d) None
    View Answer

    Correct answer: A — @app.route()

  4. What is the output of below code?
    1 python
    2 @app.route("/")
    3 def home():
    4 return "Eduinq"
    5 (Accessing "/")
    a) Eduinq
    b) Error
    c) None
    d) /
    View Answer

    Correct answer: A — Eduinq

  5. Which method runs Flask app?
    a) app.run()
    b) app.start()
    c) app.execute()
    d) None
    View Answer

    Correct answer: A — app.run()

  6. What will be printed?
    1 python
    2 from flask import Flask
    3 app = Flask(__name__)
    4 print(hasattr(app,"run"))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  7. Which of the following is used for templates in Flask?
    a) Jinja2
    b) Mako
    c) Django templates
    d) None
    View Answer

    Correct answer: A — Jinja2

  8. What is the output of below code?
    1 python
    2 from flask import render_template_string
    3 print(render_template_string("Hello {{name}}",name="Eduinq"))
    a) Hello Eduinq
    b) Hello {{name}}
    c) Error
    d) None
    View Answer

    Correct answer: A — Hello Eduinq

  9. Which of the following is used for request data in Flask?
    a) request.form
    b) request.args
    c) request.json
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  10. What will be printed?
    1 python
    2 from flask import request
    3 print(hasattr(request,"form"))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  11. Which of the following is a full stack web framework in Python?
    a) Django
    b) Flask
    c) Bottle
    d) None
    View Answer

    Correct answer: A — Django

  12. What is the output of below code?
    1 python
    2 import django
    3 print(django.get_version())
    a) Django version string
    b) Error
    c) None
    d) Version
    View Answer

    Correct answer: A — Django version string

  13. Which command creates a new Django project?
    a) django-admin startproject
    b) django-admin createproject
    c) django-admin newproject
    d) None
    View Answer

    Correct answer: A — django-admin startproject

  14. What will be printed?
    1 bash
    2 django-admin startproject Eduinq
    a) Creates project Eduinq
    b) Error
    c) None
    d) Project only
    View Answer

    Correct answer: A — Creates project Eduinq

  15. Which command creates a new Django app?
    a) python manage.py startapp
    b) python manage.py createapp
    c) python manage.py newapp
    d) None
    View Answer

    Correct answer: A — python manage.py startapp

  16. What is the output of python manage.py startapp blog?
    a) Creates app blog
    b) Error
    c) None
    d) App only
    View Answer

    Correct answer: A — Creates app blog

  17. Which file contains Django project settings?
    a) settings.py
    b) urls.py
    c) models.py
    d) views.py
    View Answer

    Correct answer: A — settings.py

  18. What will be printed?
    1 python
    2 from django.conf import settings
    3 print(hasattr(settings,"INSTALLED_APPS"))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  19. Which file contains URL routing in Django?
    a) urls.py
    b) settings.py
    c) models.py
    d) views.py
    View Answer

    Correct answer: A — urls.py

  20. What is the output of below code?
    1 python
    2 from django.urls import path
    3 print(callable(path))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  21. Which file defines models in Django?
    a) models.py
    b) views.py
    c) urls.py
    d) settings.py
    View Answer

    Correct answer: A — models.py

  22. What will be printed?
    1 python
    2 from django.db import models
    3 print(hasattr(models,"Model"))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  23. Which file defines views in Django?
    a) views.py
    b) models.py
    c) urls.py
    d) settings.py
    View Answer

    Correct answer: A — views.py

  24. What is the output of below code?
    1 python
    2 from django.http import HttpResponse
    3 def home(request):
    4 return HttpResponse("Eduinq")
    5 (Accessing home view)
    a) Eduinq
    b) Error
    c) None
    d) HttpResponse
    View Answer

    Correct answer: A — Eduinq

  25. Which file defines URL patterns in Django?
    a) urls.py
    b) views.py
    c) models.py
    d) settings.py
    View Answer

    Correct answer: A — urls.py

  26. What will be printed?
    1 python
    2 from django.urls import path
    3 print(callable(path))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  27. Which of the following is Django's ORM feature?
    a) QuerySets
    b) SQLAlchemy
    c) Raw SQL only
    d) None
    View Answer

    Correct answer: A — QuerySets

  28. What is the output of below code?
    1 python
    2 from django.db import models
    3 print(issubclass(models.Model,object))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  29. Which command runs Django development server?
    a) python manage.py runserver
    b) python manage.py startserver
    c) python manage.py server
    d) None
    View Answer

    Correct answer: A — python manage.py runserver

  30. What will be printed?
    1 bash
    2 python manage.py runserver
    a) Starts server
    b) Error
    c) None
    d) Server only
    View Answer

    Correct answer: A — Starts server

  31. Which of the following is Flask's default server?
    a) Werkzeug
    b) Gunicorn
    c) uWSGI
    d) None
    View Answer

    Correct answer: A — Werkzeug

  32. What is the output of below code?
    1 python
    2 from flask import Flask
    3 app = Flask(__name__)
    4 print(app.static_url_path)
    a) /static
    b) Error
    c) None
    d) static
    View Answer

    Correct answer: A — /static

  33. Which of the following is Django's template language?
    a) Django Template Language (DTL)
    b) Jinja2
    c) Mako
    d) None
    View Answer

    Correct answer: A — Django Template Language (DTL)

  34. What will be printed?
    1 html
    2 {{ "Eduinq"|upper }}
    a) EDUINQ
    b) Eduinq
    c) Error
    d) None
    View Answer

    Correct answer: A — EDUINQ

  35. Which of the following is Flask's default template engine?
    a) Jinja2
    b) DTL
    c) Mako
    d) None
    View Answer

    Correct answer: A — Jinja2

  36. What is the output of below code?
    1 python
    2 from flask import render_template_string
    3 print(render_template_string("{{'Eduinq'|lower}}"))
    a) eduinq
    b) Eduinq
    c) Error
    d) None
    View Answer

    Correct answer: A — eduinq

  37. Which of the following is used for database migrations in Django?
    a) python manage.py migrate
    b) python manage.py makemigrations
    c) Both A and B
    d) None
    View Answer

    Correct answer: C — Both A and B

  38. What will be printed?
    1 bash
    2 python manage.py makemigrations
    a) Creates migration files
    b) Error
    c) None
    d) Migration only
    View Answer

    Correct answer: A — Creates migration files

  39. Which of the following is used for Django admin interface?
    a) admin.site.register()
    b) admin.site.add()
    c) admin.site.create()
    d) None
    View Answer

    Correct answer: A — admin.site.register()

  40. What is the output of below code?
    1 python
    2 from django.contrib import admin
    3 print(hasattr(admin.site,"register"))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  41. Which of the following is Flask's extension for database?
    a) Flask-SQLAlchemy
    b) Flask-DB
    c) Flask-ORM
    d) None
    View Answer

    Correct answer: A — Flask-SQLAlchemy

  42. What will be printed?
    1 python
    2 from flask_sqlalchemy import SQLAlchemy
    3 print(callable(SQLAlchemy))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  43. Which of the following is Django's default database?
    a) SQLite
    b) MySQL
    c) PostgreSQL
    d) None
    View Answer

    Correct answer: A — SQLite

  44. What is the output of below code?
    1 python
    2 from django.conf import settings
    3 print(settings.DATABASES['default']['ENGINE'])
    a) django.db.backends.sqlite3
    b) Error
    c) None
    d) sqlite
    View Answer

    Correct answer: A — django.db.backends.sqlite3

  45. Which of the following is used for Flask REST API?
    a) Flask-RESTful
    b) Flask-API
    c) Flask-Rest
    d) None
    View Answer

    Correct answer: A — Flask-RESTful

  46. What will be printed?
    1 python
    2 from flask_restful import Resource
    3 print(issubclass(Resource,object))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  47. Which of the following is used for Django REST API?
    a) Django REST framework
    b) Django API
    c) Django-Restful
    d) None
    View Answer

    Correct answer: A — Django REST framework

  48. What is the output of below code?
    1 python
    2 import rest_framework
    3 print(hasattr(rest_framework,"serializers"))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  49. Which of the following is used for Flask sessions?
    a) flask.session
    b) flask.sessions
    c) flask.cookies
    d) None
    View Answer

    Correct answer: A — flask.session

  50. What will be printed?
    1 python
    2 from flask import Flask,session
    3 app = Flask(__name__)
    4 app.secret_key="Eduinq"
    5 with app.test_request_context():
    6 session["user"]="Eduinq"
    7 print(session["user"])
    a) Eduinq
    b) Error
    c) None
    d) user
    View Answer

    Correct answer: A — Eduinq

Quick Links to Explore