What is the right way to use a server-side language to create a website? Do I have to write every webpage in python (print “” etc.) or should I use the server-side just when i want to access a database,for example, and than format the output via javascript?
Thank you in advance!
What is the right way to use a server-side language to create a website?
Share
At least two things to consider, when chosing what to do on the server side:
1. Security: Anything you send to the client side will be accessible to the receiver as plain text (the javascript too). Only send data once you’re certain about the clients identity (i.e. logged in). Therefore, anything security sensitive should happen on the server side.
2. Processing time v.s. network load: If a lot of users are doing a lot of different calculations with a data set (i.e. sorting, summarizing, sub-totalling etc.), the server CPU can be offloaded by sending raw data (granted pt. 1 is taken care of), and let each client handle the calculations. On the other hand, this might cause a lot of users to request too much data, which can degrade network performance.
As a consequence: If uncertain, do as much as possible on the server side. If not uncertain, the question is void:-)
As for the other part of your question, regarding how to generate the HTML: consider using a web-framework like Django. This will give you an abstraction layer, which yields much functionality pr. line of code. Of course, this way a lot of stuff happens “behind the scenes”, which gives you less direct control, but usually the benefits outweigh the disadvantage.