Pengembangan web adalah istilah umum untuk membuat konsep, membuat, menyebarkan, dan mengoperasikan aplikasi website dan antarmuka pemrograman aplikasi untuk Website. Show Penggunaan Python dalam Pengembangan WebPython dapat digunakan untuk membangun aplikasi web sisi server. Sementara kerangka web tidak diperlukan untuk membangun aplikasi web, jarang sekali pengembang tidak akan menggunakan pustaka sumber terbuka yang ada untuk mempercepat kemajuan mereka dalam membuat aplikasi mereka berfungsi. Python tidak digunakan di browser web. Bahasa yang dijalankan di browser seperti Chrome, Firefox, dan Internet Explorer adalah JavaScript. Proyek seperti pyjs dapat dikompilasi dari Python ke JavaScript. Namun, sebagian besar pengembang Python menulis aplikasi web mereka menggunakan kombinasi Python dan JavaScript. Python dieksekusi di sisi server sementara JavaScript diunduh ke klien dan dijalankan oleh browser web. Untuk membuat website dengan menggunakan Python sebagai bahasa pemrogramanya, caranya sangat mudah. Tetapi perlu diingat bahwa sebelumnya Anda sudah harus menguasai HTML, CSS dan Javascript. Web Framework PythonFramework pengembangan web pada python yang paling populer dan mudah dipelajari ada Django dan Flask FlaskFlask adalah sebuah microframework web python yang mudah untuk dipelajari, mudah diinstal dan pengembangan yang sangat simpel. Berikut adalah beberapa kelebihanya :
Instalasi Flask Hello World Web App dengan Flask
Buka http://localhost:5000/ dibrowser anda dan akan muncul DjangoDjango adalah kerangka kerja Python Web tingkat tinggi yang menangani banyak kerumitan pengembangan Web, sehingga Anda dapat fokus untuk menulis aplikasi tanpa perlu menemukan kembali roda. Kelebihan Framework Django dibanding yang lain adalah pada segi skalabilitas. Framework ini cocok untuk pengembangan aplikasi besar. Untuk menginstal Django jalankan perintah dibawah ini : Setelah terinstal, buat direktori /django-hello/ untuk aplikasi Anda. Dalam direktori ini buat file hello.py dengan code dibawah ini: Here's a generic way to do things which at least means that you don't have to surround each and every
NB
*I looked at the source code: 0, which subclasses the single class 8 (builtin)**However at the bottom of you find "requests.exceptions.RequestException" at the time of writing (2022-02)... but it links to the above page: confusing. Usage is very simple:
First you check the response: if it's
Given that the stack trace is logged automatically you often need no more than that... (... potentially sparing a great deal of boilerplate!)To cross the Ts, when a json object is expected to be returned: If, as above, an exception gives your non-technical user a message "No response", and a non-200 status "Bad response", I suggest that
These may or may not prevent the code from continuing. ... and in fact to my mind it is worth making the process even more generic. These next functions, for me, typically cut down 20 lines of code using the above 1 to about 3, and make most of your handling and your log messages standardised. More than a handful of requests calls in your project and the code gets a lot nicer and less bloated:
Example call (NB with this version, the "deliverable" is either an exception or a response which delivers a json structure):
So the "visual log" message seen by the user in the case of missing key "status_text", for example, would be "Anomalous response checking index XYZ. See log." (and the log would give a more detailed technical message, constructed automatically, including the stack trace but also details of the missing key in question). NB
PS Yes, I do know about the 4 Python module (a "thin wrapper" around requests ). All the above is for illustration purposes. |