-
Notifications
You must be signed in to change notification settings - Fork 0
From Request to Template: How webpages load in Sidekick
Building a webpage in django requires working with lots of files. The process is complicated, but its complexity allows us to do some really cool stuff. Big-picture, we're in a client-server model dealing with request and response objects.
-
User sends request: The user types sidekick.apu.edu in their browser and hits enter.
-
Server receives request: The server receives the request, converts to https if need be, and then passes the request to Django.
-
Django routes request: Django's routing system uses urls.py files to figure out which view function it should pass the request to.
-
Application view function:
The view function will use the parameters from the request to generate or collect the information needed to build a webpage. The view function is where you'll collect any data from the database that you'll need and assemble it together into a python dictionary that gets passed into the project view -
Authorize user: Check to make sure the user's credentials are valid. If not, redirect them to the signin page.
-
Project view function: The project view function (sidekick/views.py) adds in the information necessary to load the content for each webpage (like the current MoD or the user's stars and badges). Every app view function should call this function to render templates or else vital context data will be missing.
-
Django template: The template file specified by the application view function is loaded up with all the data accumulated in the Application and Project view functions. The Django Template Engine transforms the templates into the html, css, and javascript that gets returned to the user!
-
Return response object