MIL-005: documentation, wiki and release check #36
No files matched your search
@@ -0,0 +1,23 @@
|
|||||||
|
# Flask dag 54: 100 Days of Code
|
||||||
|
|
||||||
|
[English](Home) · **Dansk** · [Bahasa Malaysia](Home-ms)
|
||||||
|
|
||||||
|
Kørbare, testede løsninger til dag 54 i Udemys "100 Days of Code: The Complete Python Pro Bootcamp". Wikien forklarer forelæsning for forelæsning, hvad koden gør, og hvad vi fik ud af forelæsningen.
|
||||||
|
|
||||||
|
## Forelæsninger
|
||||||
|
|
||||||
|
| Trin | Side | Emne |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 1 | [Forelæsning 1](Lecture-1-Backend-Overview-da) | Frontend, backend og request-response-cyklussen |
|
||||||
|
| 2 | [Forelæsning 2](Lecture-2-Hello-Flask-da) | Den første Flask-server |
|
||||||
|
| 3 | [Forelæsning 3](Lecture-3-Command-Line-da) | Kommandolinjen |
|
||||||
|
| 4 | [Forelæsning 4](Lecture-4-Name-and-Main-da) | `__name__` og `__main__` |
|
||||||
|
| 5 | [Forelæsning 5](Lecture-5-First-Class-Functions-da) | Funktioner som førsteklasses objekter |
|
||||||
|
| 6 | [Forelæsning 6](Lecture-6-Decorators-da) | Dekoratører og `@`-syntaksen |
|
||||||
|
|
||||||
|
Start med [Opsætning og kørsel](Setup-and-Run-da) for at oprette et lokalt `.venv` og køre koden og testene.
|
||||||
|
|
||||||
|
## Links
|
||||||
|
|
||||||
|
- [Repository](https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/054-flask)
|
||||||
|
- [Issue tracker](https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/054-flask/issues)
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# Flask Hari 54: 100 Days of Code
|
||||||
|
|
||||||
|
[English](Home) · [Dansk](Home-da) · **Bahasa Malaysia**
|
||||||
|
|
||||||
|
Penyelesaian Hari 54 bagi kursus Udemy "100 Days of Code: The Complete Python Pro Bootcamp" yang boleh dijalankan dan telah diuji. Wiki ini menerangkan, kuliah demi kuliah, apa yang dilakukan oleh kod dan apa yang kita pelajari daripada setiap kuliah.
|
||||||
|
|
||||||
|
## Kuliah
|
||||||
|
|
||||||
|
| Langkah | Halaman | Topik |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 1 | [Kuliah 1](Lecture-1-Backend-Overview-ms) | Bahagian hadapan, bahagian belakang dan kitaran permintaan-respons |
|
||||||
|
| 2 | [Kuliah 2](Lecture-2-Hello-Flask-ms) | Pelayan Flask yang pertama |
|
||||||
|
| 3 | [Kuliah 3](Lecture-3-Command-Line-ms) | Baris arahan |
|
||||||
|
| 4 | [Kuliah 4](Lecture-4-Name-and-Main-ms) | `__name__` dan `__main__` |
|
||||||
|
| 5 | [Kuliah 5](Lecture-5-First-Class-Functions-ms) | Fungsi sebagai objek kelas pertama |
|
||||||
|
| 6 | [Kuliah 6](Lecture-6-Decorators-ms) | Penghias (decorator) dan sintaks `@` |
|
||||||
|
|
||||||
|
Mulakan dengan [Persediaan dan Jalankan](Setup-and-Run-ms) untuk mencipta `.venv` setempat serta menjalankan kod dan ujian.
|
||||||
|
|
||||||
|
## Pautan
|
||||||
|
|
||||||
|
- [Repositori](https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/054-flask)
|
||||||
|
- [Penjejak isu](https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/054-flask/issues)
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# Flask Day 54: 100 Days of Code
|
||||||
|
|
||||||
|
**English** · [Dansk](Home-da) · [Bahasa Malaysia](Home-ms)
|
||||||
|
|
||||||
|
Runnable, tested solutions for Day 54 of Udemy's "100 Days of Code: The Complete Python Pro Bootcamp". The wiki explains, lecture by lecture, what the code does and what we gained from the lecture.
|
||||||
|
|
||||||
|
## Lectures
|
||||||
|
|
||||||
|
| Step | Page | Topic |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 1 | [Lecture 1](Lecture-1-Backend-Overview) | Frontend, backend and the request-response cycle |
|
||||||
|
| 2 | [Lecture 2](Lecture-2-Hello-Flask) | The first Flask server |
|
||||||
|
| 3 | [Lecture 3](Lecture-3-Command-Line) | The command line |
|
||||||
|
| 4 | [Lecture 4](Lecture-4-Name-and-Main) | `__name__` and `__main__` |
|
||||||
|
| 5 | [Lecture 5](Lecture-5-First-Class-Functions) | Functions as first-class objects |
|
||||||
|
| 6 | [Lecture 6](Lecture-6-Decorators) | Decorators and the `@` syntax |
|
||||||
|
|
||||||
|
Start with [Setup and Run](Setup-and-Run) to create a local `.venv` and run the code and the tests.
|
||||||
|
|
||||||
|
## Links
|
||||||
|
|
||||||
|
- [Repository](https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/054-flask)
|
||||||
|
- [Issue tracker](https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/054-flask/issues)
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Forelæsning 1: Frontend, backend og request-response-cyklussen
|
||||||
|
|
||||||
|
[English](Lecture-1-Backend-Overview) · **Dansk** · [Bahasa Malaysia](Lecture-1-Backend-Overview-ms)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Hvad forelæsningen handler om
|
||||||
|
|
||||||
|
Forelæsningen adskiller det, brugeren ser (frontend: HTML, CSS og JavaScript), fra det, applikationen gør bag kulisserne (backend: Python, Java, Ruby og andre). En backend har tre dele: klienten, serveren og databasen. En restaurant er en god analogi: spisesalen er klienten, køkkenet er serveren, og spisekammeret er databasen. I request-response-cyklussen spørger klienten, serveren forbereder og henter data fra databasen, og svaret sendes tilbage til klienten. Flask anbefales til begyndere og små projekter; Django er det andet velkendte valg.
|
||||||
|
|
||||||
|
## Hvad vi fik ud af det
|
||||||
|
|
||||||
|
- Et ordforråd til at tale om webapplikationer: klient, server, database, request, response.
|
||||||
|
- En grund til at vælge Flask: det er småt og lader os se hver del af cyklussen.
|
||||||
|
- Viden om, at resten af kurset bygger hver af disse dele op trin for trin.
|
||||||
|
|
||||||
|
## I dette repository
|
||||||
|
|
||||||
|
Diagrammet er tegnet ud fra `docs/images/sources/lecture-01.html`; der er ingen kode til denne forelæsning.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Kuliah 1: Bahagian hadapan, bahagian belakang dan kitaran permintaan-respons
|
||||||
|
|
||||||
|
[English](Lecture-1-Backend-Overview) · [Dansk](Lecture-1-Backend-Overview-da) · **Bahasa Malaysia**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Apa yang dibincangkan dalam kuliah
|
||||||
|
|
||||||
|
Kuliah ini membezakan apa yang dilihat oleh pengguna (bahagian hadapan: HTML, CSS dan JavaScript) daripada apa yang dilakukan oleh aplikasi di sebalik tabir (bahagian belakang: Python, Java, Ruby dan lain-lain). Bahagian belakang mempunyai tiga komponen: klien, pelayan dan pangkalan data. Analoginya ialah sebuah restoran: ruang makan ialah klien, dapur ialah pelayan dan stor makanan ialah pangkalan data. Dalam kitaran permintaan-respons, klien membuat permintaan, pelayan menyediakan dan mengambil data daripada pangkalan data, dan respons dihantar kembali kepada klien. Flask disyorkan untuk pemula dan projek kecil; Django ialah pilihan lain yang terkenal.
|
||||||
|
|
||||||
|
## Apa yang kita peroleh
|
||||||
|
|
||||||
|
- Kosa kata untuk bercakap tentang aplikasi web: klien, pelayan, pangkalan data, permintaan, respons.
|
||||||
|
- Sebab untuk memilih Flask: ia kecil dan membolehkan kita melihat setiap bahagian kitaran itu.
|
||||||
|
- Pengetahuan bahawa seluruh kursus membina setiap komponen ini langkah demi langkah.
|
||||||
|
|
||||||
|
## Dalam repositori ini
|
||||||
|
|
||||||
|
Gambar rajah dilukis daripada `docs/images/sources/lecture-01.html`; tiada kod untuk kuliah ini.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Lecture 1: Frontend, backend and the request-response cycle
|
||||||
|
|
||||||
|
**English** · [Dansk](Lecture-1-Backend-Overview-da) · [Bahasa Malaysia](Lecture-1-Backend-Overview-ms)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## What the lecture covers
|
||||||
|
|
||||||
|
The lecture separates what the user sees (the frontend: HTML, CSS and JavaScript) from what the application does behind the scenes (the backend: Python, Java, Ruby and others). A backend has three parts: the client, the server and the database. A restaurant is the analogy: the dining area is the client, the kitchen is the server and the pantry is the database. In the request-response cycle the client asks, the server prepares and fetches data from the database, and the response goes back to the client. Flask is recommended for beginners and small projects; Django is the other well-known choice.
|
||||||
|
|
||||||
|
## What we gained
|
||||||
|
|
||||||
|
- A vocabulary for talking about web applications: client, server, database, request, response.
|
||||||
|
- A reason to choose Flask: it is small and lets us see every part of the cycle.
|
||||||
|
- The knowledge that the rest of the course builds each of these parts step by step.
|
||||||
|
|
||||||
|
## In this repository
|
||||||
|
|
||||||
|
The diagram is drawn from `docs/images/sources/lecture-01.html`; there is no code for this lecture.
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Forelæsning 2: Den første Flask-server
|
||||||
|
|
||||||
|
[English](Lecture-2-Hello-Flask) · **Dansk** · [Bahasa Malaysia](Lecture-2-Hello-Flask-ms)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Hvad forelæsningen handler om
|
||||||
|
|
||||||
|
Et bibliotek bliver kaldt af din kode, men et framework kalder din kode og bestemmer strukturen. Forelæsningen opretter den mindste mulige Flask-applikation i en fil med navnet `hello.py` (aldrig `flask.py`, som ville skjule biblioteket), installerer Flask med `pip`, peger `FLASK_APP` på filen og starter serveren med `flask run`. Browseren viser derefter "Hello, World!" fra den lokale adresse. `Ctrl+C` stopper serveren, så to applikationer ikke kæmper om den samme port.
|
||||||
|
|
||||||
|
## Hvad vi fik ud af det
|
||||||
|
|
||||||
|
- Forskellen mellem et bibliotek og et framework.
|
||||||
|
- En fungerende webserver på seks linjer: `app = Flask(__name__)`, en rute til `/` og en funktion, der returnerer tekst.
|
||||||
|
- Hvordan `FLASK_APP` fortæller Flask, hvilken fil der skal køres.
|
||||||
|
- En vane med at teste ruten med Flasks testklient i stedet for en browser.
|
||||||
|
|
||||||
|
## I dette repository
|
||||||
|
|
||||||
|
Kode: `src/flask_day_54/presentation/hello.py` (ruten `hello_world`), use casen `application/get_greeting.py` og konstanten `GREETING`. Tests: `tests/e2e/test_hello_app.py`.
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Kuliah 2: Pelayan Flask yang pertama
|
||||||
|
|
||||||
|
[English](Lecture-2-Hello-Flask) · [Dansk](Lecture-2-Hello-Flask-da) · **Bahasa Malaysia**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Apa yang dibincangkan dalam kuliah
|
||||||
|
|
||||||
|
Sebuah pustaka dipanggil oleh kod anda, tetapi sebuah rangka kerja (framework) memanggil kod anda dan menentukan strukturnya. Kuliah ini mencipta aplikasi Flask yang paling kecil dalam fail bernama `hello.py` (jangan sekali-kali `flask.py`, kerana ia akan menyembunyikan pustaka itu), memasang Flask dengan `pip`, menunjukkan fail itu melalui `FLASK_APP` dan memulakan pelayan dengan `flask run`. Pelayar kemudian memaparkan "Hello, World!" daripada alamat setempat. `Ctrl+C` menghentikan pelayan supaya dua aplikasi tidak berebut port yang sama.
|
||||||
|
|
||||||
|
## Apa yang kita peroleh
|
||||||
|
|
||||||
|
- Perbezaan antara pustaka dan rangka kerja.
|
||||||
|
- Pelayan web yang berfungsi dalam enam baris: `app = Flask(__name__)`, satu laluan (route) untuk `/` dan satu fungsi yang memulangkan teks.
|
||||||
|
- Cara `FLASK_APP` memberitahu Flask fail mana yang hendak dijalankan.
|
||||||
|
- Tabiat menguji laluan dengan klien ujian Flask dan bukannya pelayar.
|
||||||
|
|
||||||
|
## Dalam repositori ini
|
||||||
|
|
||||||
|
Kod: `src/flask_day_54/presentation/hello.py` (laluan `hello_world`), kes guna `application/get_greeting.py` dan pemalar `GREETING`. Ujian: `tests/e2e/test_hello_app.py`.
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Lecture 2: The first Flask server
|
||||||
|
|
||||||
|
**English** · [Dansk](Lecture-2-Hello-Flask-da) · [Bahasa Malaysia](Lecture-2-Hello-Flask-ms)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## What the lecture covers
|
||||||
|
|
||||||
|
A library is called by your code, but a framework calls your code and decides the structure. The lecture creates the smallest Flask application in a file named `hello.py` (never `flask.py`, which would hide the library), installs Flask with `pip`, points `FLASK_APP` at the file and starts the server with `flask run`. The browser then shows "Hello, World!" from the local address. `Ctrl+C` stops the server so that two applications do not fight over the same port.
|
||||||
|
|
||||||
|
## What we gained
|
||||||
|
|
||||||
|
- The difference between a library and a framework.
|
||||||
|
- A working web server in six lines: `app = Flask(__name__)`, a route for `/` and a function that returns text.
|
||||||
|
- How `FLASK_APP` tells Flask which file to run.
|
||||||
|
- A habit of testing the route with Flask's test client instead of a browser.
|
||||||
|
|
||||||
|
## In this repository
|
||||||
|
|
||||||
|
Code: `src/flask_day_54/presentation/hello.py` (route `hello_world`), the use case `application/get_greeting.py` and the constant `GREETING`. Tests: `tests/e2e/test_hello_app.py`.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Forelæsning 3: Kommandolinjen
|
||||||
|
|
||||||
|
[English](Lecture-3-Command-Line) · **Dansk** · [Bahasa Malaysia](Lecture-3-Command-Line-ms)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Hvad forelæsningen handler om
|
||||||
|
|
||||||
|
Terminalen taler med operativsystemets kerne (kernel) gennem skallen (shell) (en pistacienød: kernen er nødden, skallen er den ydre skal). Den giver udviklere kontrol og hastighed. Forelæsningen viser `pwd` (hvor er jeg), `ls` (hvad er her), `cd` (gå derhen), `mkdir` (ny mappe), `touch` (ny fil) og `rm` (slet). `rm -rf` fjerner en mappe og alt i den uden at spørge, så den kræver forsigtighed. Windows har lignende kommandoer: `cd`, `dir`, `type nul > file`, `del`, `rmdir /s /q`.
|
||||||
|
|
||||||
|
## Hvad vi fik ud af det
|
||||||
|
|
||||||
|
- De seks kommandoer, vi bruger hver dag til at bevæge os rundt og administrere filer.
|
||||||
|
- En tydelig advarsel om de to destruktive kommandoer, skrevet ind i koden som data.
|
||||||
|
- Selvtillid til at bruge terminalen i stedet for kun grafiske værktøjer.
|
||||||
|
|
||||||
|
## I dette repository
|
||||||
|
|
||||||
|
Kode: `src/flask_day_54/domain/cli_basics.py` angiver kommandoerne med deres Windows-former. Skærmbilledet viser rigtige kommandoer kørt i en midlertidig mappe. Tests: `tests/unit/test_cli_basics.py`.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Kuliah 3: Baris arahan
|
||||||
|
|
||||||
|
[English](Lecture-3-Command-Line) · [Dansk](Lecture-3-Command-Line-da) · **Bahasa Malaysia**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Apa yang dibincangkan dalam kuliah
|
||||||
|
|
||||||
|
Terminal berinteraksi dengan kernel sistem pengendalian melalui shell (seperti buah pistachio: kernel ialah isinya, shell ialah kulit luarnya). Ia memberi pembangun kawalan dan kelajuan. Kuliah ini menunjukkan `pwd` (di mana saya), `ls` (apa yang ada di sini), `cd` (pergi ke sana), `mkdir` (folder baharu), `touch` (fail baharu) dan `rm` (padam). `rm -rf` membuang sebuah folder dan segala isinya tanpa bertanya, jadi ia perlu digunakan dengan berhati-hati. Windows mempunyai arahan yang serupa: `cd`, `dir`, `type nul > file`, `del`, `rmdir /s /q`.
|
||||||
|
|
||||||
|
## Apa yang kita peroleh
|
||||||
|
|
||||||
|
- Enam arahan yang kita gunakan setiap hari untuk bergerak dan mengurus fail.
|
||||||
|
- Amaran yang jelas untuk dua arahan yang memusnahkan, ditulis dalam kod sebagai data.
|
||||||
|
- Keyakinan untuk menggunakan terminal dan bukan hanya alat bergrafik.
|
||||||
|
|
||||||
|
## Dalam repositori ini
|
||||||
|
|
||||||
|
Kod: `src/flask_day_54/domain/cli_basics.py` menyenaraikan arahan beserta bentuknya dalam Windows. Tangkapan skrin menunjukkan arahan sebenar yang dijalankan dalam folder sementara. Ujian: `tests/unit/test_cli_basics.py`.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Lecture 3: The command line
|
||||||
|
|
||||||
|
**English** · [Dansk](Lecture-3-Command-Line-da) · [Bahasa Malaysia](Lecture-3-Command-Line-ms)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## What the lecture covers
|
||||||
|
|
||||||
|
The terminal talks to the operating system's kernel through the shell (a pistachio: the kernel is the nut, the shell is the outer shell). It gives developers control and speed. The lecture shows `pwd` (where am I), `ls` (what is here), `cd` (go there), `mkdir` (new folder), `touch` (new file) and `rm` (delete). `rm -rf` removes a folder and everything in it without asking, so it needs care. Windows has similar commands: `cd`, `dir`, `type nul > file`, `del`, `rmdir /s /q`.
|
||||||
|
|
||||||
|
## What we gained
|
||||||
|
|
||||||
|
- The six commands we use every day to move around and manage files.
|
||||||
|
- A clear warning for the two destructive commands, written into the code as data.
|
||||||
|
- Confidence to use the terminal instead of only graphical tools.
|
||||||
|
|
||||||
|
## In this repository
|
||||||
|
|
||||||
|
Code: `src/flask_day_54/domain/cli_basics.py` lists the commands with their Windows forms. The screenshot shows real commands run in a temporary folder. Tests: `tests/unit/test_cli_basics.py`.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Forelæsning 4: __name__ og __main__
|
||||||
|
|
||||||
|
[English](Lecture-4-Name-and-Main) · **Dansk** · [Bahasa Malaysia](Lecture-4-Name-and-Main-ms)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Hvad forelæsningen handler om
|
||||||
|
|
||||||
|
`__name__` er en indbygget variabel, der indeholder navnet på det aktuelle modul. Når en fil køres direkte, sætter Python den til `"__main__"`; når filen importeres, indeholder den modulets navn. Med `if __name__ == "__main__":` kan en fil bestemme, hvad der kun kører, når den er hovedprogrammet, for eksempel `app.run()`. Det giver en anden måde at starte Flask-serveren på ved siden af `flask run`, og det gør det nemt at starte og stoppe under udvikling.
|
||||||
|
|
||||||
|
## Hvad vi fik ud af det
|
||||||
|
|
||||||
|
- Reglen om, at kode kører korrekt, uanset om en fil køres eller importeres.
|
||||||
|
- En `main()`-funktion i `hello.py`, der kun kaldes under `__main__`-tjekket, så import aldrig starter en server.
|
||||||
|
- Et testet eksempel (`describe_name`), der forklarer de to tilfælde med ord.
|
||||||
|
|
||||||
|
## I dette repository
|
||||||
|
|
||||||
|
Kode: `src/flask_day_54/presentation/hello.py` (`main`) og `src/flask_day_54/domain/name_demo.py`. Tests: `tests/unit/test_name_demo.py` og `tests/e2e/test_hello_main.py`.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Kuliah 4: __name__ dan __main__
|
||||||
|
|
||||||
|
[English](Lecture-4-Name-and-Main) · [Dansk](Lecture-4-Name-and-Main-da) · **Bahasa Malaysia**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Apa yang dibincangkan dalam kuliah
|
||||||
|
|
||||||
|
`__name__` ialah pemboleh ubah terbina dalam yang menyimpan nama modul semasa. Apabila sesebuah fail dijalankan terus, Python menetapkannya kepada `"__main__"`; apabila fail itu diimport, ia menyimpan nama modul. Semakan `if __name__ == "__main__":` membolehkan sesebuah fail menentukan apa yang dijalankan hanya apabila ia ialah atur cara utama, contohnya `app.run()`. Ini memberi cara kedua untuk memulakan pelayan Flask, selain `flask run`, dan memudahkan memulakan serta menghentikan pelayan semasa pembangunan.
|
||||||
|
|
||||||
|
## Apa yang kita peroleh
|
||||||
|
|
||||||
|
- Peraturan bahawa kod berjalan dengan betul sama ada fail dijalankan atau diimport.
|
||||||
|
- Fungsi `main()` dalam `hello.py` yang hanya dipanggil di bawah semakan `__main__`, jadi mengimportnya tidak akan memulakan pelayan.
|
||||||
|
- Contoh yang telah diuji (`describe_name`) yang menerangkan kedua-dua kes dengan kata-kata.
|
||||||
|
|
||||||
|
## Dalam repositori ini
|
||||||
|
|
||||||
|
Kod: `src/flask_day_54/presentation/hello.py` (`main`) dan `src/flask_day_54/domain/name_demo.py`. Ujian: `tests/unit/test_name_demo.py` dan `tests/e2e/test_hello_main.py`.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Lecture 4: __name__ and __main__
|
||||||
|
|
||||||
|
**English** · [Dansk](Lecture-4-Name-and-Main-da) · [Bahasa Malaysia](Lecture-4-Name-and-Main-ms)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## What the lecture covers
|
||||||
|
|
||||||
|
`__name__` is a built-in variable that holds the name of the current module. When a file is run directly Python sets it to `"__main__"`; when the file is imported it holds the module name. Checking `if __name__ == "__main__":` lets a file decide what runs only when it is the main program, for example `app.run()`. That gives a second way to start the Flask server, next to `flask run`, and it makes starting and stopping easy during development.
|
||||||
|
|
||||||
|
## What we gained
|
||||||
|
|
||||||
|
- The rule that code runs correctly whether a file is run or imported.
|
||||||
|
- A `main()` function in `hello.py` that is only called under the `__main__` check, so importing it never starts a server.
|
||||||
|
- A tested example (`describe_name`) that explains the two cases in words.
|
||||||
|
|
||||||
|
## In this repository
|
||||||
|
|
||||||
|
Code: `src/flask_day_54/presentation/hello.py` (`main`) and `src/flask_day_54/domain/name_demo.py`. Tests: `tests/unit/test_name_demo.py` and `tests/e2e/test_hello_main.py`.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Forelæsning 5: Funktioner som førsteklasses objekter
|
||||||
|
|
||||||
|
[English](Lecture-5-First-Class-Functions) · **Dansk** · [Bahasa Malaysia](Lecture-5-First-Class-Functions-ms)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Hvad forelæsningen handler om
|
||||||
|
|
||||||
|
I Python er en funktion et objekt ligesom et heltal eller en streng: den kan sendes som argument, defineres inde i en anden funktion og returneres fra den. Funktionen `calculate` tager to tal og en anden funktion (`add` eller `subtract`) og anvender den. En indlejret funktion kan kaldes af sin overordnede funktion, men ikke udefra. En funktion kan returnere en indlejret funktion, og den, der kalder, gemmer den i en variabel og kalder den senere. Værktøjet Python Tutor viser trinnene visuelt.
|
||||||
|
|
||||||
|
## Hvad vi fik ud af det
|
||||||
|
|
||||||
|
- Ideen bag dekoratører: en funktion, der modtager en funktion og returnerer en funktion.
|
||||||
|
- Reglen for scope ved indlejrede funktioner, bekræftet af en test af, at det indlejrede navn ikke kan nås udefra.
|
||||||
|
- Opgavens navne (`add`, `subtract`, `calculate`) i kode, som andre kursister kan læse og køre.
|
||||||
|
|
||||||
|
## I dette repository
|
||||||
|
|
||||||
|
Kode: `src/flask_day_54/domain/first_class_functions.py`. Tests: `tests/unit/test_first_class_functions.py`.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Kuliah 5: Fungsi sebagai objek kelas pertama
|
||||||
|
|
||||||
|
[English](Lecture-5-First-Class-Functions) · [Dansk](Lecture-5-First-Class-Functions-da) · **Bahasa Malaysia**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Apa yang dibincangkan dalam kuliah
|
||||||
|
|
||||||
|
Dalam Python, fungsi ialah objek seperti integer atau rentetan: ia boleh dihantar sebagai argumen, ditakrifkan di dalam fungsi lain dan dipulangkan daripadanya. Fungsi `calculate` menerima dua nombor dan satu fungsi lain (`add` atau `subtract`) lalu menggunakannya. Fungsi bersarang boleh dipanggil oleh fungsi induknya tetapi tidak dari luar. Sesebuah fungsi boleh memulangkan fungsi bersarang, dan pemanggil menyimpannya dalam pemboleh ubah serta memanggilnya kemudian. Alat Python Tutor menunjukkan langkah-langkahnya secara visual.
|
||||||
|
|
||||||
|
## Apa yang kita peroleh
|
||||||
|
|
||||||
|
- Idea di sebalik penghias (decorator): fungsi yang menerima fungsi dan memulangkan fungsi.
|
||||||
|
- Peraturan skop untuk fungsi bersarang, disahkan oleh ujian bahawa nama fungsi bersarang tidak boleh dicapai dari luar.
|
||||||
|
- Nama-nama dalam tugasan (`add`, `subtract`, `calculate`) dalam kod yang boleh dibaca dan dijalankan oleh peserta kursus yang lain.
|
||||||
|
|
||||||
|
## Dalam repositori ini
|
||||||
|
|
||||||
|
Kod: `src/flask_day_54/domain/first_class_functions.py`. Ujian: `tests/unit/test_first_class_functions.py`.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Lecture 5: Functions as first-class objects
|
||||||
|
|
||||||
|
**English** · [Dansk](Lecture-5-First-Class-Functions-da) · [Bahasa Malaysia](Lecture-5-First-Class-Functions-ms)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## What the lecture covers
|
||||||
|
|
||||||
|
In Python a function is an object like an integer or a string: it can be passed as an argument, defined inside another function and returned from it. The `calculate` function takes two numbers and another function (`add` or `subtract`) and applies it. A nested function can be called by its parent but not from outside. A function can return a nested function, and the caller stores it in a variable and calls it later. The tool Python Tutor shows the steps visually.
|
||||||
|
|
||||||
|
## What we gained
|
||||||
|
|
||||||
|
- The idea behind decorators: a function that receives a function and returns a function.
|
||||||
|
- The scope rule for nested functions, confirmed by a test that the nested name is not reachable from outside.
|
||||||
|
- The assignment's names (`add`, `subtract`, `calculate`) in code that other course participants can read and run.
|
||||||
|
|
||||||
|
## In this repository
|
||||||
|
|
||||||
|
Code: `src/flask_day_54/domain/first_class_functions.py`. Tests: `tests/unit/test_first_class_functions.py`.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Forelæsning 6: Dekoratører og @-syntaksen
|
||||||
|
|
||||||
|
[English](Lecture-6-Decorators) · **Dansk** · [Bahasa Malaysia](Lecture-6-Decorators-ms)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Hvad forelæsningen handler om
|
||||||
|
|
||||||
|
En dekoratør tilføjer adfærd til en eksisterende funktion uden at redigere den. Forelæsningen opsummerer først førsteklasses funktioner samt indlejring og returnering af funktioner og introducerer derefter `@`-syntaksen: at skrive `@make_bold` over en funktion er det samme som `say_hello = make_bold(say_hello)`. Flask bruger den samme idé til sine ruter: `@app.route("/")`. Med `functools.wraps` beholder den indpakkede funktion sit navn.
|
||||||
|
|
||||||
|
## Hvad vi fik ud af det
|
||||||
|
|
||||||
|
- `@`-syntaksen som genvej til at sende en funktion til en wrapper.
|
||||||
|
- Stabling af dekoratører: den nærmest funktionen kører først, så `@make_bold @make_emphasis @make_underlined` giver `<b><em><u>...</u></em></b>`.
|
||||||
|
- En forståelse af, hvad `@app.route("/")` gør i de næste forelæsninger.
|
||||||
|
|
||||||
|
## I dette repository
|
||||||
|
|
||||||
|
Kode: `src/flask_day_54/domain/decorators.py`. Tests: `tests/unit/test_decorators.py`.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Kuliah 6: Penghias (decorator) dan sintaks @
|
||||||
|
|
||||||
|
[English](Lecture-6-Decorators) · [Dansk](Lecture-6-Decorators-da) · **Bahasa Malaysia**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Apa yang dibincangkan dalam kuliah
|
||||||
|
|
||||||
|
Penghias (decorator) menambah tingkah laku pada fungsi sedia ada tanpa mengubah suai fungsi itu. Kuliah ini mula-mula mengulang kaji fungsi kelas pertama, fungsi bersarang dan pemulangan fungsi, kemudian memperkenalkan sintaks `@`: menulis `@make_bold` di atas sesebuah fungsi sama dengan `say_hello = make_bold(say_hello)`. Flask menggunakan idea yang sama untuk laluan (route)nya: `@app.route("/")`. Dengan `functools.wraps`, fungsi yang dibalut mengekalkan namanya.
|
||||||
|
|
||||||
|
## Apa yang kita peroleh
|
||||||
|
|
||||||
|
- Sintaks `@` sebagai jalan pintas untuk menghantar fungsi kepada pembalut.
|
||||||
|
- Penghias bertindan: yang paling hampir dengan fungsi dijalankan dahulu, maka `@make_bold @make_emphasis @make_underlined` menghasilkan `<b><em><u>...</u></em></b>`.
|
||||||
|
- Kefahaman tentang apa yang dilakukan oleh `@app.route("/")` dalam kuliah-kuliah seterusnya.
|
||||||
|
|
||||||
|
## Dalam repositori ini
|
||||||
|
|
||||||
|
Kod: `src/flask_day_54/domain/decorators.py`. Ujian: `tests/unit/test_decorators.py`.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Lecture 6: Decorators and the @ syntax
|
||||||
|
|
||||||
|
**English** · [Dansk](Lecture-6-Decorators-da) · [Bahasa Malaysia](Lecture-6-Decorators-ms)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## What the lecture covers
|
||||||
|
|
||||||
|
A decorator adds behaviour to an existing function without editing it. The lecture first recaps first-class functions, nesting and returning functions, then introduces the `@` syntax: writing `@make_bold` above a function is the same as `say_hello = make_bold(say_hello)`. Flask uses the same idea for its routes: `@app.route("/")`. With `functools.wraps` the wrapped function keeps its name.
|
||||||
|
|
||||||
|
## What we gained
|
||||||
|
|
||||||
|
- The `@` syntax as shorthand for passing a function to a wrapper.
|
||||||
|
- Stacking decorators: the one nearest the function runs first, so `@make_bold @make_emphasis @make_underlined` gives `<b><em><u>...</u></em></b>`.
|
||||||
|
- An understanding of what `@app.route("/")` does in the next lectures.
|
||||||
|
|
||||||
|
## In this repository
|
||||||
|
|
||||||
|
Code: `src/flask_day_54/domain/decorators.py`. Tests: `tests/unit/test_decorators.py`.
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# Opsætning og kørsel
|
||||||
|
|
||||||
|
[English](Setup-and-Run) · **Dansk** · [Bahasa Malaysia](Setup-and-Run-ms)
|
||||||
|
|
||||||
|
## Krav
|
||||||
|
|
||||||
|
Python 3.13 eller nyere. Flask er kun nødvendigt til webforelæsningerne (det valgfrie tillæg `web`); pytest ligger i tillægget `dev`.
|
||||||
|
|
||||||
|
## Opret og brug et lokalt `.venv`
|
||||||
|
|
||||||
|
Windows (PowerShell):
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
python -m venv .venv
|
||||||
|
.\.venv\Scripts\Activate.ps1
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
python -m pip install -e ".[dev]"
|
||||||
|
```
|
||||||
|
|
||||||
|
macOS og Linux:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 -m venv .venv
|
||||||
|
source .venv/bin/activate
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
python -m pip install -e ".[dev]"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Kør serveren
|
||||||
|
|
||||||
|
```bash
|
||||||
|
flask --app flask_day_54.presentation.hello run
|
||||||
|
python -m flask_day_54.presentation.hello
|
||||||
|
```
|
||||||
|
|
||||||
|
Åbn `http://127.0.0.1:5000/` og stop serveren med `Ctrl+C`.
|
||||||
|
|
||||||
|
## Kør testene
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python -m pytest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Hvad vi fik ud af det
|
||||||
|
|
||||||
|
- Én gentagelig måde at starte på fra en ren udgave af koden: et lokalt `.venv`, en opdateret pip og en redigerbar installation.
|
||||||
|
- To måder at starte Flask-serveren på og en testsuite, der kører uden en browser.
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# Persediaan dan Jalankan
|
||||||
|
|
||||||
|
[English](Setup-and-Run) · [Dansk](Setup-and-Run-da) · **Bahasa Malaysia**
|
||||||
|
|
||||||
|
## Keperluan
|
||||||
|
|
||||||
|
Python 3.13 atau lebih baharu. Flask hanya diperlukan untuk kuliah web (tambahan `web` yang pilihan); pytest terdapat dalam tambahan `dev`.
|
||||||
|
|
||||||
|
## Cipta dan gunakan `.venv` setempat
|
||||||
|
|
||||||
|
Windows (PowerShell):
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
python -m venv .venv
|
||||||
|
.\.venv\Scripts\Activate.ps1
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
python -m pip install -e ".[dev]"
|
||||||
|
```
|
||||||
|
|
||||||
|
macOS dan Linux:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 -m venv .venv
|
||||||
|
source .venv/bin/activate
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
python -m pip install -e ".[dev]"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Jalankan pelayan
|
||||||
|
|
||||||
|
```bash
|
||||||
|
flask --app flask_day_54.presentation.hello run
|
||||||
|
python -m flask_day_54.presentation.hello
|
||||||
|
```
|
||||||
|
|
||||||
|
Buka `http://127.0.0.1:5000/` dan hentikan pelayan dengan `Ctrl+C`.
|
||||||
|
|
||||||
|
## Jalankan ujian
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python -m pytest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Apa yang kita peroleh
|
||||||
|
|
||||||
|
- Satu cara yang boleh diulang untuk bermula daripada salinan kerja yang bersih: `.venv` setempat, pip yang dikemas kini dan pemasangan boleh suntingan (editable).
|
||||||
|
- Dua cara untuk memulakan pelayan Flask, dan satu set ujian yang berjalan tanpa pelayar.
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# Setup and Run
|
||||||
|
|
||||||
|
**English** · [Dansk](Setup-and-Run-da) · [Bahasa Malaysia](Setup-and-Run-ms)
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
Python 3.13 or newer. Flask is only needed for the web lectures (the optional `web` extra); pytest is in the `dev` extra.
|
||||||
|
|
||||||
|
## Create and use a local `.venv`
|
||||||
|
|
||||||
|
Windows (PowerShell):
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
python -m venv .venv
|
||||||
|
.\.venv\Scripts\Activate.ps1
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
python -m pip install -e ".[dev]"
|
||||||
|
```
|
||||||
|
|
||||||
|
macOS and Linux:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 -m venv .venv
|
||||||
|
source .venv/bin/activate
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
python -m pip install -e ".[dev]"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run the server
|
||||||
|
|
||||||
|
```bash
|
||||||
|
flask --app flask_day_54.presentation.hello run
|
||||||
|
python -m flask_day_54.presentation.hello
|
||||||
|
```
|
||||||
|
|
||||||
|
Open `http://127.0.0.1:5000/` and stop the server with `Ctrl+C`.
|
||||||
|
|
||||||
|
## Run the tests
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python -m pytest
|
||||||
|
```
|
||||||
|
|
||||||
|
## What we gained
|
||||||
|
|
||||||
|
- One repeatable way to start from a clean checkout: a local `.venv`, an upgraded pip and an editable install.
|
||||||
|
- Two ways to start the Flask server, and a test suite that runs without a browser.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Flask Day 54 - Udemy 100 Days of Code. Code, tests and project documents: [repository](https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/054-flask).
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
**Flask Day 54**
|
||||||
|
|
||||||
|
- [Home](Home)
|
||||||
|
- [Setup and Run](Setup-and-Run)
|
||||||
|
- [Lecture 1: Backend overview](Lecture-1-Backend-Overview)
|
||||||
|
- [Lecture 2: Hello Flask](Lecture-2-Hello-Flask)
|
||||||
|
- [Lecture 3: Command line](Lecture-3-Command-Line)
|
||||||
|
- [Lecture 4: __name__ and __main__](Lecture-4-Name-and-Main)
|
||||||
|
- [Lecture 5: First-class functions](Lecture-5-First-Class-Functions)
|
||||||
|
- [Lecture 6: Decorators](Lecture-6-Decorators)
|
||||||
|
|
||||||
|
**Languages**
|
||||||
|
|
||||||
|
- English: [Home](Home)
|
||||||
|
- Dansk: [Hjem](Home-da)
|
||||||
|
- Bahasa Melayu: [Utama](Home-ms)
|
||||||
Reference in new issue
Block a user