Classroom "rules":
Tell us about yourself:
Online development: Github account
Local development:
Local development (option 2):
A client sends an HTTP request:
GET /index.html HTTP/1.1
Host: www.example.com
The server sends back an HTTP response:
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Content-Length: 208
<!DOCTYPE html>
<html>
<head>
<title>Example Domain</title>
</head>
<body>
<h1>Example Domain</h1>
<p>This domain is to be used for illustrative examples in documents.</p>
</body>
</html>
Webpages are made up of three languages:
The most basic server just serves up HTML and multimedia files from a file system.
Server-side code is also useful for anything that requires access to persistent data or needs an additional layer of security than allowed in the client.
The http module in the Python standard library can run a basic server.
⚠️ It is not recommended for production.
It's handy for learning and local development, however...
A file server serves up files and folders according to their path in the file system. Also known as a static server.
Run a file server from any folder:
python3 -m http.server 8080
👩🏼💻 Repo: github.com/pamelafox/python-simple-server-example/
The server code is in server.py.
Uses the http
module to dynamically generate responses.
Run the server:
python3 server.py
Flask, an external package, is a lightweight framework for server requests and responses.
Apps written in Flask:
👀 Demo: tinyurl.com/simple-flask-website
👩🏼💻 Repo: github.com/pamelafox/simple-flask-server-example/
Most of the server code is in app.py. Uses Flask to generate responses for each route
Run the server:
python3 app.py
Using this repo:
github.com/pamelafox/simple-flask-server-example/
🙋🏼♀️🙋🏾♀️🙋🏽♀️ Let us know if you need any help! 🙋🏻♀️🙋🏽♂️🙋🏿♀️
Web apps store data in databases that needs to be shared across multiple users/computers.
👀 Demo: tinyurl.com/flask-db-quiz
👩🏼💻 Repo: github.com/pamelafox/flask-db-quiz-example/
Most of the server code is in app.py. Uses SQLAlchemy for database interaction.
Run the server:
python3 app.py
Django, an external library, is a fairly "opinionated" framework for server-side code. Includes an ORM for database interaction.
Apps written in Django:
👀 Demo: tinyurl.com/django-db-reviews
👩🏼💻 Repo: github.com/pamelafox/django-quiz-app/
Important server files:
models.py
, urls.py
, views.py
, admin.py
Run DB migrations and server:
python manage.py migrate
python manage.py runserver
Using this repo:
github.com/pamelafox/django-quiz-app/
🙋🏼♀️🙋🏾♀️🙋🏽♀️ Let us know if you need any help! 🙋🏻♀️🙋🏽♂️🙋🏿♀️
When your website is hosted on a server, it means other users on the Internet can access it.
Many possible hosts:
Consider:
Azure Container Apps | Azure Functions | |||
Azure Kubernetes Service | Container Management | Azure App Service | Serverless | |
Environment | Containers | PaaS | ||
Cloud | Azure |
For Flask/Django, App Service is easiest way to get started.
Databases | PostGreSQL, MySQL, CosmosDB, ... |
---|---|
Storage | Blob Storage, Files, Archive Storage, ... |
Networking | DNS Zone, Virtual Network, VPN Gateway, ... |
Caching | CDN, Front Door, ... |
Security | Key Vault, Security Center, ... |
Machine Learning | Translator, Bot Service, Computer Vision, ... |
...and more! |
Repo: github.com/pamelafox/django-quiz-app
Using the Azure Dev CLI:
azd up
Repo: github.com/Azure-Samples/msdocs-django-postgresql-sample-app
Using the Azure Dev CLI:
azd up
azd up
. If prompted, login to your Azure account.
azd down
to un-deploy the app (so that you don't waste cloud resources unnecessarily).