tags? - [ ] show_fields() - [x] as_p() - [ ] as_table() - [ ] fields() # You have found a bug in Django and you want to submit a patch. Which is the correct procedure? - [ ] Fork the Django repository GitHub. - [ ] Submit a pull request. - [x] all of these answers. - [ ] Run Django's test suite. # Django supplies sensible default values for settings. In which Python module can you find these settings? - [ ] django.utils.default_settings.py - [ ] django.utils.global_settings.py - [ ] django.conf.default_settings.py - [x] django.conf.global_settings.py # Which variable name is best according to PEP 8 guidelines? - [ ] numFingers - [ ] number-of-Fingers - [x] number_of_fingers - [ ] finger_num # A project has accumulated 500 migrations. Which course of action would you pursue? - [ ] Manually merge your migration files to reduce the number - [ ] Don't worry about the number - [ ] Try to minimize the number of migrations - [x] Use squashmigrations to reduce the number # What does an F() object allow you when dealing with models? - [x] perform db operations without fetching a model object - [ ] define db transaction isolation levels - [ ] use aggregate functions more easily - [ ] build reusable QuerySets # Which is not a Django filed type for integers? - [ ] SmallIntegerField - [x] NegativeIntegerField - [ ] BigAutoField - [ ] PositiveIntegerField # Which will show the currently installed version? - [ ] print (django.version) - [ ] import django django.getVersion() - [x] import django django.get_version() - [ ] python -c django --version # You should use the http method `___` to read data and `___` to update or create data - [ ] READ; WRITE - [x] GET; POST - [ ] POST; GET - [ ] GET; PATCH # When should you employ the POST method over GET for submitting data? - [ ] when efficiency is important - [ ] when you want the data to be cached - [ ] when you want to use your browser to help with debugging - [x] when the data in the form may be sensitive # When to use the Django sites framework? - [x] if your single installation powers more than one site - [ ] if you need to serve static as well as dynamic content - [ ] if you want your app have a fully qualified domain name - [ ] if you are expecting more than 10.000 users # Which infrastructure do you need: `title=models.charfield(max_length=100, validators=[validate_spelling])` - [ ] inizialized array called validators - [x] a validators file containing a function called validate_spelling imported at the top of model - [ ] a validators file containing a function called validate imported at the top of model - [ ] spelling package imported at the top of model # What decorator is used to require that a view accepts only the get and head methods? - [x] require_safe() - [ ] require_put() - [ ] require_post() - [ ] require_get() # 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) ``` - [x] ```python 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 ``` # What is a callable that takes a value and raises an error if the value fails? - [x] validator - [ ] deodorizer - [ ] mediator - [ ] regular expression # 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 - [ ] rest_framework.permissions.IsAdminUser - [x] rest_framework.permissions.IsAuthenticated - [ ] rest_framework.permissions.IsAuthorized - [ ] rest_framework.permissions.IsRegistered # Which command would you use to apply a migration? - [ ] makemigration - [ ] update_db - [ ] applymigration - [x] migrate # Which type of class allows QuerySets and model instances to be converted to native Python data types for use in APIs? - [ ] objectwriters - [x] serializers - [ ] picklers - [ ] viewsets # How should the code end? ``` { percentage if spark >= 50 percentage } Lots of spark {percentage elif spark == 42 percentage} ``` - [ ] { percentage else percentage} - [x] {percentage endif percentage} - [ ] Nothing needed - [ ] {percentage end percentage} # Which code block will create a serializer? ``` from rest_framework import serializers from .models import Planet ``` - [x] ``` 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 ``` # Which class allows you to automatically create a Serializer class with fields and validators that correspond to your model's fields? - [x] ModelSerializer - [ ] Model - [ ] DataSerializer - [ ] ModelToSerializer # Which command to access the built-in admin tool for the first time? - [ ] django-admin setup - [ ] django-admin runserver - [ ] python manage.py createuser - [x] python manage.py createsuperuser # Virtual environments are for managing dependencies. Which granularity works best? - [x] you should set up a new virtualenv for each Django project - [ ] They should not be used - [ ] Use the same venv for all your Django work - [ ] Use a new venv for each Django app # What executes various Django commands such as running a webserver or creating an app? - [ ] migrate.py - [ ] wsgi.py - [x] manage.py - [ ] runserver # What do Django best practice suggest should be "fat"? - [x] models - [ ] controllers - [ ] programmers - [ ] clients # Which is not part of Django's design philosophy? - [ ] Loose Coupling - [ ] Less Code - [ ] Fast Development - [x] Implicit over explicit # What is the result of this template code? ``` {{"live long and prosper"|truncate:3}} ``` - [x] live long and ... - [ ] live long and - [ ] a compilation error - [ ] liv # 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) ``` - [ ] line 1 - [x] It depends on how many results return by query. - [ ] It depends on cache. - [ ] line 2 # You are building a web application using a React front end and a Django back end. For what will you need to provision?\*\* - [ ] an NGINX web server - [ ] a NoSQL database - [ ] a larger hard drive - [ ] CORS middleware # To expose an existing model via an API endpoint, what do you need to implement?\*\* - [ ] an HTTP request - [ ] a JSON object - [ ] a query - [x] a serializer # How would you stop Django from performing database table creation or deletion operations via migrations for a particular model?\*\* - [ ] Run the `migrate` command with `--exclude=[model_name]`. - [ ] Move the model definition from `models.py` into its own file. - [x] Set `managed=False` inside the model. - [ ] Don't run the `migrate` command. # what method can you use to check if form data has changed when using a form instance? - [x] has_changed() - [ ] its_changed() - [ ] has_updated() - [ ] None of This # What is WSGI? - [x] a server - [ ] an interface specification - [ ] a Python module - [ ] a framework # Which generic view should be used for displaying the tittles of all Django Reinhardt's songs? - [ ] DetailView - [ ] TittleView - [ ] SongView - [x] ListView # Which statement is most accurate, regarding using the default SQLite database on your local/development machine but Postgres in production - [x] There's less chance of introducing bugs since SQLite already works out the box - [ ] It's fine, you just need to keep both instances synchronized - [ ] It's a bad idea and could lead to issues down the road - [ ] It's the most efficient way to build a project # Why might you want to write a custom model Manager? - [ ] to perform database queries - [ ] to set up a database for testing - [x] to modify the initial QuerySet that the Manager returns - [ ] to filter the results that a database query returns # In Django, what are used to customize the data that is sent to the templates? - [ ] models - [x] views - [ ] forms - [ ] serializers # To complete the conditional, what should this block of code end with? ```shell % if sparles >= 50 % Lots of sparkles! % elif sparkles == 42 % The answer to life, the universe, and everything! ``` - [x] `% endif %` - [ ] Nothing else is needed. - [ ] `% end%` - [ ] `% else %` # When should you employ the POST method over the GET method for submitting data from a form? - [x] when the data in the form may be sensitive - [ ] when you want the data to be cached - [ ] when you want to use your browser to help with debugging - [ ] when efficiency is important # What is a callable that takes a value and raises an error if the value fails to meet some criteria? - [ ] mediator - [x] validator - [ ] regular expression - [ ] deodorizer # 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. - [ ] request.META; FileField - [ ] request.FILES; BLOBField - [x] request.FILES; FileField - [ ] request.META.Files; CLOBField # What python module might be used to store the current state of a Django model in a file? - [x] pickle - [ ] struct - [ ] marshal - [ ] serialize # To add a new app to an existing Django project, you must edit the **_ section of the _** file. - [ ] ALLOWED_HOSTS; settings.py - [ ] APPS; manage.py - [x] INSTALLED_APPS; settings.py - [ ] TEMPLATES; urls.py # Which is not a third-party package commonly used for authentication? - [ ] django-guardian - [ ] django-rest-auth - [ ] authtoken - [x] django-rest-framework-jwt # Which function in the django.urls package can help you avoid hardcoding URLS by generating a URL given the name of a view? - [ ] get_script_prefix() - [ ] redirect() - [x] reverse() - [ ] resolve() # Which is Fictional HTTP request method? - [ ] POST - [ ] PUT - [x] PAUSE - [ ] PATCH # Which helper function is not provided as a part of django.shortcuts package? ref- - [x] render_to_request() - [ ] render() - [ ] redirect() - [ ] get_object_or_404() [Reference](https://docs.djangoproject.com/en/4.0/topics/http/shortcuts/#:~:text=The%20package%20django.,controlled%20coupling%20for%20convenience's%20sake) # Which is a nonstandard place to store templates? - [x] at the root level of a project - [ ] inside the application - [ ] in the database - [ ] on Github # If you left the 8080 off the command python manage.py runserver 8080 what port would Django use as default? - [x] 8080 - [ ] 80 - [ ] 8000 - [ ] It would fail to start
Join our newsletter to stay in the loop for new contents.