linkedin-skill-assessments-quizzes

Django

Q1. To cache your entire site for an application in Django, you add all except which of these settings?

Reference: Django comes with a robust cache system that lets you save dynamic pages, so they don’t have to be computed for each request. For convenience, Django offers cache with different granularity — from entire website to pages to part of pages to DB query results to any objects in memory. Cache middleware. If enabled, each Django-powered page will be cached based on URL.

Q2. In which programming language is Django written?

Q3. To automatically provide a value for a field, or to do validation that requires access to more than a single field, you should override the ___ method in the ___ class.

Q4. A client wants their site to be able to load “Rick & Morty” episodes by number or by title—e.g., shows/3/3 or shows/picklerick. Which URL pattern do you recommend?

url(r'shows/<int:season>/<int:episode>/', views.episode_number),
url(r'shows/<slug:episode_name>/', views.episode_name)
path('shows/<int:season>/<int:episode>/', views.episode_number),
path('shows/<slug:episode_name>/', views.episode_name)
path('shows/<int:season>/<int:episode>', views.episode_number),
path('shows/<slug:episode_name>/', views.episode_number)
url(r'^show/(?P<season>[0-9]+)/(?P<episode>[0-9]+)/$', views.episode_number),
url(r'^show/(?P<episode_name>[\w-]+)/', views.episode_name

Q5. How do you determine at startup time if a piece of middleware should be used?

Q6. How do you turn off Django’s automatic HTML escaping for part of a web page?

Q7. Which step would NOT help you troubleshoot the error “django-admin: command not found”?

Q8. Every time a user is saved, their quiz_score needs to be recalculated. Where might be an ideal place to add this logic?

Q9. What is the correct way to begin a class called “Rainbow” in Python?

Q10. You have inherited a Django project and need to get it running locally. It comes with a requirements.txt file containing all its dependencies. Which command should you use?

Q11. Which best practice is NOT relevant to migrations?

Q12. What will this URL pattern match? url(r’^$’, views.hello)

Q13. What is the typical order of an HTTP request/response cycle in Django?

Q14. Django’s class-based generic views provide which classes that implement common web development tasks?

Q15. Which skills do you need to maintain a set of Django templates?

Q16. How would you define the relationship between a star and a constellation in a Django model?

class Star(models.Model):
name = models.CharField(max_length=100)
class Constellation(models.Model):
stars = models.ManyToManyField(Star)
class Star(models.Model):
constellation = models.ForeignKey(Constellation, on_delete=models.CASCADE)
class Constellation(models.Model):
stars = models.ForeignKey(Star, on_delete=models.CASCADE)
class Star(models.Model):
name = models.CharField(max_length=100)
class Constellation(models.Model):
stars = models.OneToManyField(Star)
class Star(models.Model):
constellation = models.ManyToManyField(Constellation)
class Constellation(models.Model):
name = models.CharField(max_length=100)

Q17. Which is NOT a valid step in configuring your Django 2.x instance to serve up static files such as images or CSS?

Q18. What is the correct way to make a variable available to all of your templates?

Q19. Should you create a custom user model for new projects?

Q20. You want to create a page that allows editing of two classes connected by a foreign key (e.g., a question and answer that reside in separate tables). What Django feature can you use?

Q21. Why are QuerySets considered “lazy”?

Q22. You receive a MultiValueDictKeyError when trying to access a request parameter with the following code: request.GET[‘search_term’]. Which solution will NOT help you in this scenario?

Q23. Which function of Django’s Form class will render a form’s fields as a series of <p> tags?

Q24. You have found a bug in Django and you want to submit a patch. Which is the correct procedure?

Q25. Django supplies sensible default values for settings. In which Python module can you find these settings?

Q26. Which variable name is best according to PEP 8 guidelines?

Q27. A project has accumulated 500 migrations. Which course of action would you pursue?

Q28. What does an F() object allow you when dealing with models?

Q29. Which is not a Django field type for holding integers?

Q30. Which will show the currently installed version?

Q31. You should use the http method ___ to read data and ___ to update or create data

Q32. When should you employ the POST method over GET for submitting data?

Q33. When to use the Django sites framework?

Q34. Which infrastructure do you need:

title=models.charfield(max_length=100, validators=[validate_spelling])

Q35. What decorator is used to require that a view accepts only the get and head methods?

Q36. How would you define the relation between a book and an author - book has only one author.

class Author (models.model):
book=models.foreignkey(Book,on_delete=models.cascade)
class Book(models.model):
name=models.charfield(max_length=100)
class Author (models.model):
name=models.charfield(max_length=100)
class Book(models.model):
author=models.foreignkey(Author,on_delete=models.cascade)
class Author (models.model):
name=models.charfield(max_length=100)
class Book(models.model):
author=models.foreignkey(Author)
class Author (models.model):
name=models.charfield(max_length=100)
class Book(models.model):
author=models.foreignkey(Author,on_delete=models.cascade)
class Author (models.model):
name=models.charfield(max_length=100)
class Book(models.model):
author=Author.name

Q37. What is a callable that takes a value and raises an error if the value fails?

Q38. To secure an API endpoint, making it accessible to registered users only, you can replace the rest_framework.permissions.allowAny value in the default_permissions section of your settings.py to

Q39. Which command would you use to apply a migration?

Q40. Which type of class allows QuerySets and model instances to be converted to native Python data types for use in APIs?

Q41. How should the code end?

{ percentage if spark >= 50 percentage }
Lots of spark
{percentage elif spark == 42 percentage}

Q42. Which code block will create a serializer?

from rest_framework import serializers
from .models import Planet
class PlanetSerializer(serializers.ModelSerializer):
class Meta:
model=Planet
fields=('name','position', 'mass', 'rings')
from rest_framework import serializers
from .models import Planet
class PlanetSerializer():
class Meta:
fields=('name','position', 'mass', 'rings')
model=Planet
from django.db import serializers
from .models import Planet
class PlanetSerializer(serializers.ModelSerializer):
fields=('name','position', 'mass', 'rings')
model=Sandwich
from django.db import serializers
from .models import Planet
class PlanetSerializer(serializers.ModelSerializer):
class Meta:
fields=('name')
model=Planet

Q43. Which class allows you to automatically create a Serializer class with fields and validators that correspond to your model’s fields?

Q44. Which command to access the built-in admin tool for the first time?

Q45. Virtual environments are for managing dependencies. Which granularity works best?

Q46. What executes various Django commands such as running a webserver or creating an app?

Q47. What do Django best practice suggest should be “fat”?

Q48. Which is not part of Django’s design philosophy?

Q49. What is the result of this template code?

live long and…

Q50. When does this code load data into memory?

1 sandwiches = Sandwich.objects.filter(is_vegan=True)
2 for sandwich in sandwiches:
3   print(sandwich.name + " - " + sandwich.spice_level)

Q51. You are building a web application using a React front end and a Django back end. For what will you need to provision?**

Q52. To expose an existing model via an API endpoint, what do you need to implement?**

Q53. How would you stop Django from performing database table creation or deletion operations via migrations for a particular model?

Q54. what method can you use to check if form data has changed when using a form instance?

Q55. What is WSGI?

Reference link:- https://wsgi.tutorial.codepoint.net/intro

Q56. Which generic view should be used for displaying the titles of all Django Reinhardt’s songs?

Q57. Which statement is most accurate, regarding using the default SQLite database on your local/development machine but Postgres in production

Q58. Why might you want to write a custom model Manager?

Q59. In Django, what are used to customize the data that is sent to the templates?

Q60. To complete the conditional, what should this block of code end with?

% if sparles >= 50 %
  Lots of sparkles!
% elif sparkles == 42 %
  The answer to life, the universe, and everything!

Q61. When should you employ the POST method over the GET method for submitting data from a form?

Q62. What is a callable that takes a value and raises an error if the value fails to meet some criteria?

Q63. You are uploading a file to Django from a form and you want to save the received file as a field on a model object. You can simply assign the file object from_to a field of type__in the model.

Q64. What python module might be used to store the current state of a Django model in a file?

Q65. To add a new app to an existing Django project, you must edit the _ section of the _ file.

Q66. Which is not a third-party package commonly used for authentication?

Q67. Which function in the django.urls package can help you avoid hardcoding URLS by generating a URL given the name of a view?

Q68. Which is Fictional HTTP request method?

Q69. Which helper function is not provided as a part of django.shortcuts package? ref-

Reference

Q70. Which is a nonstandard place to store templates?

Q71. If you left the 8080 off the command python manage.py runserver 8080 what port would Django use as default?

Q72. Which statement about Django apps is false?

Q73. Which characters are illegal in template variable names?

Reference

Q74. Which is not a valid closing template tag?

Q75. When would you need to use the reverse_lazy utility function instead of reverse?

Q76. What is the purpose of the __init__.py file?

Reference

Q77. What python package can be used to edit numbers into more readable form like “1200000” to “1.2 million”?

Q78. Where would you find the settings.py file?

Q79. What would you write to define the relationship between a book and an author--assuming a book has only one author-in a Django model?

class Author (models.Model):
  name = models. CharField (max_length=100)
class Book(models .Model):
  author = models. ForeignKey (Author, on_delete=models. CASCADE)
class Author (models.Model):
  name = models. CharField(max length=100)
class Book(models .Model):
  author = models. ForeignKey (Author)
class Author (models .Model):
  name = models.CharField (max_length=100)
class Book (models .Author) :
  author = Author. name
class Author (models. Model):
  book = models. ForeignKey (Book, on_delete=models.CASCADE)
class Book(models.Model):
  name = models. CharField (max length=100)

Q80. What method can you use to check if form data has been changed when using a Form instance?

Q81. Which statement is most accurate, regarding using the default SQLite database on your local/development machine but Postgres in production?

Q82. How does Django handle URL routing?

Q83. What is the purpose of Django’s middleware?

Reference

Q84. Which of the following is true about Django’s Object-Relational Mapping (ORM)?

Q85. Which of the following is true about Django’s “many-to-many” field in a model?

Q86. Django’s class-based generic views provide which classes that implement common web development tasks?

Q87. Which skills do you need to maintain a set of Django templates?

Q88. Which is a nonstandard place to store templates?

Q89. If you left the 8080 off the command python manage.py runserver 8080 what port would Django use as default?

Q90. What is the purpose of Django’s Object-Relational Mapping (ORM)?

Q91. In Django, what does the term “migration” refer to?

Q92. What is the purpose of Django’s “context” in the context of rendering templates?

Q93. What does the Django QuerySet class represent?

Q94. In Django, what is the purpose of the “collectstatic” management command?

Q95. What is the Django Admin site used for?

Q96. What does Django’s “middleware” refer to?

Q97. What is the primary purpose of Django’s “migration files”?

Q98. Which authentication system does Django provide out of the box?

Q99. In Django, what does the “Model-View-Controller” (MVC) architectural pattern refer to?

Q100. What is the purpose of Django’s “templates”?