PYTHON DJANGO EXAM WITH QUESTIONS AND ANSWERS Describe the major actions that occur after the user enters a URL that refers to a site managed by Django. - ANSWER On the client side, the browser will use DNS to get the IP address corresponding to the URL, use this address to commun icate with the server (via HTTP running over TCP/ip), send the HTTP (GET) request to the server. The web server will have been configured to hand the URL to the Django site, at which point it uses the info in urls.py (as describe d above). This process maps the URL request to a view function (or class); the view code typical ly uses models to interact with a database and apply business logic to the data. The data is then handed to an HTML template(s) for rendering, which results in HTML, etc. being returned to the browser. What is the difference between a project and an app, and why does Django have both? - ANSWER A project is the entire application as a whole, and the app refers to a submodule of the project. Apps are not related to other apps in the project a nd in theory, can be copy-pasted to another project and still work without modifications. In general, how does the DRY Principle apply to software development? (note : this is not just a Python/Django thing). What problems can arise from not foll owing DRY principles? - ANSWER DRY is the "don't repeat yourself" principle and means that repetition of information should be avoided. This is applied t o software development by splicing code into reusable, smaller sections, so the same code/information is not duplicated in other areas. If the DRY principle is not followed, then code can become more difficult to manage. For example, when logi c changes need to be made, instead of changing them in one location the changes would have to be made in every place that uses that logic. Describe/Explain one example of where the DRY principle is applied in the design of Django. - ANSWER Model code is used to generate ORM (object-relational-mapping) interface to the DB. This keeps you from havi ng to keep SQL queries in sync with changes to the class's data. The data is reflected in only one place (the model), versus in both a class declaration and sql statemen ts. The model is used to generate default forms/templates that correspond to the model data (again, versus maintaining all forms separately and keeping them in sync with data in classes). What exactly is a "migration"? - ANSWER Migrations are Django's ways to send changes in your models to the database. It's basically just waiting to se nd SQL that was already written to the database until you tell it to. It is easy to use SQL to just drop tables and then re-run a sql script to create the new tables that I want, so why are migrations useful? - ANSWER Migrations allows you to map your SQL perfectly to your Models and OOP specifically. Migrations also guarantee you don't repeat yourself, and that a bunch o f database changes you make at a time work when you send them all to the database together. It reduces error, as it automatically helps with stuff like foreign keys and other more complicated changes. path('<int:question_id>/', views.detail, name='detail' ), Is question_id a "keyword"? What does this notation have to match up with? - ANSWER In this case, question_id is sent to the view function as a k eyword argument where the detail view must take a variable named 'question_id' as an argument. a. What does the {{ .... }} syntax mean? - ANSWER Will render variables that are within the current context of the template. b. What does the {% .... %} syntax mean? - ANSWER Code within will be interpreted as python What are the main steps required to start a Django project? - ANSWER Install Virtual Environment (Optional) Create the virtual environment directory (python -m venv folder-name) Activate the virtual environment (folder-name\Scripts\activate.bat) Install Django using pip (pip install django)
Voordelen van het kopen van samenvattingen bij Stuvia op een rij:
Verzekerd van kwaliteit door reviews
Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!
Snel en makkelijk kopen
Je betaalt supersnel en eenmalig met iDeal, creditcard of Stuvia-tegoed voor de samenvatting. Zonder lidmaatschap.
Focus op de essentie
Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!
Veelgestelde vragen
Wat krijg ik als ik dit document koop?
Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.
Tevredenheidsgarantie: hoe werkt dat?
Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.
Van wie koop ik deze samenvatting?
Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper luzlinkuz. Stuvia faciliteert de betaling aan de verkoper.
Zit ik meteen vast aan een abonnement?
Nee, je koopt alleen deze samenvatting voor €13,75. Je zit daarna nergens aan vast.