0% found this document useful (0 votes)
5 views17 pages

Full Stack Python MCQ

The document is a multiple-choice questionnaire covering various aspects of Django, including basic concepts, models, views, templates, forms, middleware, settings, authentication, and deployment best practices. Each question is followed by four answer options, with the correct answer indicated. The content is structured in sections, each focusing on specific Django functionalities and features.

Uploaded by

Anupriyan kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views17 pages

Full Stack Python MCQ

The document is a multiple-choice questionnaire covering various aspects of Django, including basic concepts, models, views, templates, forms, middleware, settings, authentication, and deployment best practices. Each question is followed by four answer options, with the correct answer indicated. The content is structured in sections, each focusing on specific Django functionalities and features.

Uploaded by

Anupriyan kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Full Stack Python MCQ

### 1-10: Basic Django Concepts

Q1. What does Django primarily follow in its architecture?


a) Model-View-Controller (MVC)
b) Model-View-Template (MVT)
c) Client-Server Model
d) Layered Architecture
Answer: b) Model-View-Template (MVT)

Q2. Which command is used to create a new Django project?


a) django startproject projectname
b) django-admin startproject projectname
c) python [Link] startproject projectname
d) django create projectname
Answer: b) django-admin startproject projectname

Q3. Which file contains the URL configurations?


a) [Link]
b) [Link]
c) [Link]
d) [Link]
Answer: c) [Link]

Q4. How do you create a new app in Django?


a) django startapp appname
b) python [Link] startapp appname
c) django createapp appname
d) [Link] createapp appname
Answer: b) python [Link] startapp appname

Q5. What is the default port on which Django development server runs?
a) 8000
b) 8080
c) 5000
d) 3000
Answer: a) 8000

[Link]
Q6. Which database does Django use by default?
a) MySQL
b) PostgreSQL
c) SQLite
d) Oracle
Answer: c) SQLite

Q7. Which file is used to configure database settings in Django?


a) [Link]
b) [Link]
c) [Link]
d) [Link]
Answer: c) [Link]

Q8. How do you run migrations in Django?


a) python [Link] migrate
b) python [Link] makemigrations
c) python [Link] runmigrations
d) python [Link] syncdb
Answer: a) python [Link] migrate

Q9. Which class is used to define a model in Django?


a) class Model
b) class DjangoModel
c) class [Link]
d) class ObjectModel
Answer: c) class [Link]

Q10. What is the purpose of Django’s [Link] file?


a) To manage database migrations
b) To execute administrative tasks like starting the server, migrations, creating apps
c) To configure project settings
d) To define URL patterns
Answer: b) To execute administrative tasks like starting the server, migrations, creating apps

[Link]
### 11-20: Django Models and ORM

Q11. Which field is used to store text in Django models?


a) CharField
b) TextField
c) StringField
d) DataField
Answer: b) TextField

Q12. How do you define a primary key in Django models?


a) primary_key=True
b) key=True
c) id=True
d) unique=True
Answer: a) primary_key=True

Q13. Which method creates the database tables for models?


a) python [Link] makemigrations
b) python [Link] migrate
c) python [Link] create_tables
d) Both a and b
Answer: d) Both a and b

Q14. How do you retrieve all objects of a model?


a) [Link]()
b) [Link]()
c) [Link]()
d) [Link]()
Answer: b) [Link]()

Q15. Which Django ORM method filters data based on conditions?


a) filter()
b) get()
c) exclude()
d) all()
Answer: a) filter()

[Link]
Q16. To retrieve a single object by primary key, which method is used?
a) get()
b) filter()
c) retrieve()
d) find()
Answer: a) get()

Q17. How do you update an object in Django ORM?


a) [Link]()
b) [Link]()
c) [Link]()
d) [Link]()
Answer: a) [Link]()

Q18. How do you delete an object in Django ORM?


a) [Link]()
b) [Link]()
c) del object
d) [Link]()
Answer: b) [Link]()

Q19. Which attribute is used to specify verbose name of a model field?


a) name
b) label
c) verbose_name
d) display_name
Answer: c) verbose_name

Q20. How do you define a one-to-many relationship in Django models?


a) ForeignKey
b) ManyToManyField
c) OneToOneField
d) RelationshipField
Answer: a) ForeignKey

[Link]
### 21-30: Django Views and Templates

Q21. Which class-based view is used to display a list of objects?


a) ListView
b) DetailView
c) CreateView
d) UpdateView
Answer: a) ListView

Q22. Which function is used to render a template in Django views?


a) render()
b) render_template()
c) show()
d) display()
Answer: a) render()

Q23. How do you pass context data to a template?


a) context dictionary in render()
b) context parameter in view function
c) context variable in template
d) Both a and b
Answer: d) Both a and b

Q24. Which template tag is used to include another template?


a) {% include %}
b) {% extend %}
c) {% load %}
d) {% import %}
Answer: a) {% include %}

Q25. How do you access a variable in Django template?


a) {{ variable_name }}
b) {% variable_name %}
c) {% variable_name %}
d) [[ variable_name ]]
Answer: a) {{ variable_name }}

[Link]
Q26. Which method is used to handle form submissions in Django?
a) POST method in view
b) GET method in view
c) Both a and b
d) Django forms handle this automatically
Answer: c) Both a and b

Q27. How do you redirect a user to another URL?


a) redirect()
b) HttpResponseRedirect()
c) both a and b
d) redirect_user()
Answer: c) both a and b

Q28. Which decorator is used to require login for a view?


a) @login_required
b) @require_login
c) @auth_required
d) @login_view
Answer: a) @login_required

Q29. How do you display static files like CSS and JS in Django templates?
a) {% static 'path/to/file' %}
b) {% load static %} before using static tags
c) Both a and b
d) Use absolute URL directly
Answer: c) Both a and b

Q30. What is the default HTTP method for a Django form?


a) GET
b) POST
c) PUT
d) DELETE
Answer: a) GET (but forms typically use POST for data submission)

[Link]
### 31-40: Django Forms and Validation

Q31. Which class is used to create a form in Django?


a) [Link]
b) [Link]
c) Both a and b
d) [Link]
Answer: c) Both a and b

Q32. How do you validate a Django form?


a) form.is_valid()
b) [Link]()
c) [Link]()
d) [Link]()
Answer: a) form.is_valid()

Q33. How do you access cleaned data after form validation?


a) form.cleaned_data
b) [Link]
c) form.cleaned_data()
d) form.get_cleaned()
Answer: a) form.cleaned_data

Q34. Which method is used to save a ModelForm?


a) [Link]()
b) [Link]()
c) [Link]()
d) [Link]()
Answer: a) [Link]()

Q35. How do you specify custom validation for a form field?


a) clean_<fieldname>() method in form class
b) validate_<fieldname>() method
c) validators argument in form field
d) Both a and c
Answer: d) Both a and c

[Link]
Q36. Which HTML attribute is used to specify that a form field is required?
a) required
b) validate
c) must have
d) check
Answer: a) required

Q37. How do you handle a form's POST request in a view?


a) Check [Link] == 'POST'
b) Instantiate form with [Link] data
c) Validate form and save if valid
d) All of the above
Answer: d) All of the above

Q38. How do you include CSRF token in a Django form?


a) {% csrf_token %} in template inside form tags
b) csrf_token variable in context
c) Automatically included in Django form
d) No need to include manually
Answer: a) {% csrf_token %}

Q39. How do you display form errors in a Django template?


a) {{ [Link] }}
b) {{ form.non_field_errors }}
c) {{ [Link] }} for individual fields
d) All of the above
Answer: d) All of the above

Q40. Which method of a Django form is used to check if the data is valid?
a) is_valid()
b) check()
c) validate()
d) verify()
Answer: a) is_valid()

[Link]
### 41-50: Django Middleware and Settings

Q41. What is middleware in Django?


a) Functions that process requests and responses globally
b) Classes that handle URL routing
c) Templates for rendering views
d) Database connection handlers
Answer: a) Functions that process requests and responses globally

Q42. Where do you add middleware classes in Django?


a) MIDDLEWARE setting in [Link]
b) INSTALLED_APPS in [Link]
c) URL configuration
d) [Link]
Answer: a) MIDDLEWARE setting in [Link]

Q43. Which setting specifies the base URL of the Django project?
a) ROOT_URLCONF
b) BASE_URL
c) STATIC_URL
d) URL_HOST
Answer: a) ROOT_URLCONF

Q44. Which setting defines the directory for static files?


a) STATICFILES_DIRS
b) STATIC_ROOT
c) STATIC_URL
d) STATICFILES_FINDERS
Answer: a) STATICFILES_DIRS

Q45. How do you enable debugging in Django?


a) DEBUG = True in [Link]
b) DEBUG = False in [Link]
c) Run server with --debug flag
d) Set DEBUG_HANDLED to True
Answer: a) DEBUG = True in [Link]

[Link]
Q46. Which setting is used to specify allowed hosts in Django?
a) ALLOWED_HOSTS
b) HOSTS
c) SITE_ALLOWED_HOSTS
d) URL_HOSTS
Answer: a) ALLOWED_HOSTS

Q47. What does the SECRET_KEY setting in Django do?


a) Used for cryptographic signing
b) Stores database password
c) Defines the project's URL
d) Sets the project name
Answer: a) Used for cryptographic signing

Q48. Which setting specifies the default language of Django?


a) LANGUAGE_CODE
b) DEFAULT_LANGUAGE
c) LANGUAGES
d) LOCALE
Answer: a) LANGUAGE_CODE

Q49. How do you enable timezone support in Django?


a) USE_TZ = True in [Link]
b) TIME_ZONE = 'UTC' in [Link]
c) Both a and b
d) No need to enable; it's on by default
Answer: c) Both a and b

Q50. Which setting determines whether Django will serve static files during development?
a) DEBUG = True
b) STATICFILES_SERVE = True
c) STATICFILES_DEBUG = True
d) STATIC_SERVE = True
Answer: a) DEBUG = True

[Link]
### 51-60: Django Admin and Authentication

Q51. How do you create an admin user in Django?


a) python [Link] createsuperuser
b) python [Link] adminuser
c) django admin createuser
d) create_user() in shell
Answer: a) python [Link] createsuperuser

Q52. Which URL pattern is used to access the Django admin interface?
a) /admin/
b) /dashboard/
c) /manage/
d) /site/
Answer: a) /admin/

Q53. How do you register a model with the Django admin site?
a) [Link](ModelName)
b) @[Link](ModelName) decorator
c) Both a and b
d) RegisterAdmin(ModelName)
Answer: c) Both a and b

Q54. Which decorator restricts access to authenticated users?


a) @login_required
b) @admin_required
c) @auth_required
d) @user_login
Answer: a) @login_required

Q55. How do you log in a user in Django?


a) login(request, user)
b) authenticate() then login()
c) login_user()
d) Both a and b
Answer: d) Both a and b

[Link]
Q56. Which method logs out a user?
a) logout(request)
b) logout_user()
c) end_session()
d) signout()
Answer: a) logout(request)

Q57. How do you check if a user is authenticated in a view?


a) [Link].is_authenticated
b) request.is_authenticated
c) [Link]
d) user.is_logged_in
Answer: a) [Link].is_authenticated

Q58. Which form class is used for login/logout in Django?


a) AuthenticationForm
b) LoginForm
c) UserForm
d) LoginModelForm
Answer: a) AuthenticationForm

Q59. How do you restrict access to a view to only logged-in users?


a) Use @login_required decorator
b) Check [Link].is_authenticated in view
c) Configure in URL pattern
d) Both a and b
Answer: d) Both a and b

Q60. How do you set login URL for redirecting when login is required?
a) LOGIN_URL in [Link]
b) LOGIN_REDIRECT_URL in [Link]
c) @login_required(login_url='/login/')
d) Both a and c
Answer: d) Both a and c

[Link]
### 61-70: Django REST Framework (Optional)

Q61. Which package is used for building REST APIs in Django?


a) Django REST Framework
b) Django API Toolkit
c) Django RestAPId) Django API
Answer: a) Django REST Framework

Q62. How do you serialize data in Django REST Framework?


a) Using [Link] classes
b) Using Django forms
c) Using JSON directly
d) Using [Link]
Answer: a) Using [Link] classes

Q63. Which class is used to create a viewset in Django REST Framework?


a) ViewSet
b) ModelViewSet
c) APIView
d) Both a and b
Answer: d) Both a and b

Q64. How do you include URL patterns for REST API views?
a) Using routers in DRF
b) Manually define URLs
c) Both a and b
d) Use API URLs automatically
Answer: c) Both a and b

Q65. How is authentication typically handled in DRF?


a) TokenAuthentication
b) SessionAuthentication
c) BasicAuthentication
d) All of the above
Answer: d) All of the above

[Link]
### 71-80: Deployment and Best Practices

Q71. Which server is commonly used for deploying Django in production?


a) Gunicorn
b) uWSGI
c) mod_wsgi with Apache
d) All of the above
Answer: d) All of the above

Q72. Why should DEBUG be set to False in production?


a) To prevent detailed error pages exposing sensitive info
b) To improve performance
c) For security reasons
d) All of the above
Answer: d) All of the above

Q73. Which database is recommended for production deployment?


a) PostgreSQL
b) MySQL
c) SQLite
d) Both a and b
Answer: d) Both a and b

Q74. How do you collect static files for deployment?


a) python [Link] collectstatic
b) [Link] static
c) python [Link] staticcollect
d) No need to collect static files
Answer: a) python [Link] collectstatic

Q75. Which environment variable is used to set Django’s secret key in production?
a) DJANGO_SECRET_KEY
b) SECRET_KEY
c) DJANGO_SECRET
d) SECRET_ENV
Answer: b) SECRET_KEY

[Link]
### 81-90: Miscellaneous

Q81. Which of these is NOT a Django built-in app?


a) [Link]
b) [Link]
c) [Link]
d) [Link]
Answer: d) [Link]

Q82. How do you enable internationalization in Django?


a) Set USE_I18N = True in [Link]
b) Set LANGUAGES in [Link]
c) Use {% trans %} template tag
d) All of the above
Answer: d) All of the above

Q83. What is the purpose of collectstatic command?


a) To gather static files into a single directory for production
b) To collect database migrations
c) To compile templates
d) To compile Python files
Answer: a) To gather static files into a single directory for production

Q84. Which command is used to start a new Django project?


a) django-admin startproject projectname
b) django startproject projectname
c) django project create projectname
d) django create projectname
Answer: a) django-admin startproject projectname

Q85. How do you run Django’s test suite?


a) python [Link] test
b) django test
c) python run_tests.py
d) [Link] run_tests
Answer: a) python [Link] test

[Link]
### 91-100: Advanced Topics

Q91. Which feature does Django provide for handling user permissions?
a) [Link].permission_required
b) Custom middleware
c) Custom decorators
d) All of the above
Answer: d) All of the above

Q92. How do you implement pagination in Django?


a) Using Django’s built-in Paginator class
b) Manually limiting queryset
c) Using third-party packages only
d) Both a and b
Answer: d) Both a and b

Q93. Which method is used to serve media files uploaded by users?


a) Serve media files during development using [Link]
b) Configure media URL and root, and serve via web server in production
c) Use static files setup for media files
d) Both a and b
Answer: d) Both a and b

Q94. How can you implement caching in Django?


a) Using cache framework with cache backends like Redis or Memcached
b) Using per-view caching decorators
c) Using template fragment caching
d) All of the above
Answer: d) All of the above

Q95. How do you handle CSRF protection in Django?


a) Using {% csrf_token %} in forms
b) Middleware enabled by default
c) Custom CSRF middleware
d) Both a and b
Answer: d) Both a and b

[Link]
Q96. Which command is used to check the health of your Django project?
a) python [Link] check
b) python [Link] health
c) django healthcheck
d) python [Link] verify
Answer: a) python [Link] check

Q97. How do you specify a custom user model in Django?


a) Subclass AbstractUser or AbstractBaseUser in [Link]
b) Set AUTH_USER_MODEL in [Link]
c) Both a and b
d) Use default User model only
Answer: c) Both a and b

Q98. Which package can be used to add rich text editing in Django admin?
a) django-ckeditor
b) django-tinymce
c) Both a and b
d) django-richtext
Answer: c) Both a and b

Q99. How do you add custom management commands in Django?


a) Create a management/commands directory inside an app and add a Python script
b) Use built-in commands only
c) Add commands in [Link]
d) Use external packages only
Answer: a) Create a management/commands directory inside an app and add a Python script

Q100. Which technique is used for version control of Django projects?


a) Git
b) SVN
c) Mercurial
d) All of the above
Answer: d) All of the above

[Link]

You might also like