8.1.
Which of the following Django command creates a new project structure for
starting a web application?
A. python [Link] startapp
B. django-admin startproject
C. python [Link] runserver
D. pip install django
ANSWER: B
8.2. In a Django project, where should you define URL routes for login and
registration pages?
A. [Link]
B. [Link]
C. [Link]
D. [Link]
ANSWER: D
8.3. Which method in Django handles the POST request when a user submits a
registration form?
A. get()
B. post()
C. form_valid()
D. save()
ANSWER: B
8.4. What is the correct way to create a new user in Django using built-in User
model?
A. User.create_user()
B. [Link]()
C. [Link]()
D. [Link].create_user()
ANSWER: D
8.5. Why is `@login_required` decorator used in Django views?
A. To allow anonymous access to the view
B. To restrict access to logged-in users only
C. To validate registration data
D. To hash the password
ANSWER: B
8.6. Which template tag is used in Django templates to generate the URL for the
login view?
A. {% url ‘login_view’ %}
B. {{ login_url }}
C. {% login ‘url’ %}
D. {% href ‘login’ %}
ANSWER: A
8.7. What must be included in the [Link] file to enable login and logout
redirection?
A. LOGIN_REDIRECT and LOGOUT_VIEW
B. LOGIN_URL and LOGOUT_URL
C. LOGIN_REDIRECT_URL and LOGOUT_REDIRECT_URL
D. LOGIN_FORM and LOGOUT_FORM
ANSWER: C
8.8. When using Django’s built-in authentication views, what is the default
template name for the login page?
A. [Link]
B. registration/[Link]
C. user_login.html
D. auth/[Link]
ANSWER: B
8.9. Which middleware ensures that the user’s authentication state is maintained
between requests?
A. SessionMiddleware
B. AuthenticationMiddleware
C. CSRF Middleware
D. SecurityMiddleware
ANSWER: B
8.10. Which of the following is the best practice for storing user passwords in
Django?
A. Plain text in database
B. Base64 encoding
C. Hashed using Django’s default hasher
D. Encrypted using custom algorithm
ANSWER: C