Python Web Development Libraries I
Total Page:16
File Type:pdf, Size:1020Kb
Python Web Development Libraries i Python Web Development Libraries About the Tutorial Python provides multiple frameworks for the web development. This tutorial covers five most commonly used python libraries which are used for web development. All the mentioned libraries in this tutorial are the first choice in certain project-specific conditions/requirements. Also, while trying to select the libraries, the developers interest (based on their queries and community support) is considered. Audience This tutorial is designed to compare the basic features of some of the most commonly used python frameworks. The target audience for this tutorial is: Anyone who wants to have a basic understanding of Django, Flask, Pyramid, Web2py and Dash libraries. Anyone who wants to compare different Python frameworks and choose the most suitable framework for their projects. Anyone who wants to explore Python web technologies in detail. Prerequisites Though there is no mandatory requirement for this tutorial, any prior knowledge on below mentioned technologies will be an added advantage: Knowledge of any web related technologies Python language Developers/users who have previously worked on any python framework will definitely find it easier to understand Copyright & Disclaimer Copyright 2018 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at [email protected] ii Python Web Development Libraries Table of Contents About the Tutorial ........................................................................................................................................... ii Audience .......................................................................................................................................................... ii Prerequisites .................................................................................................................................................... ii Copyright & Disclaimer .................................................................................................................................... ii Table of Contents ........................................................................................................................................... iii 1. Python Web Development Libraries – Introduction .................................................................................. 1 Why Web Development? ................................................................................................................................ 1 2. Python Web Development Libraries – Python Frameworks ...................................................................... 4 Django ............................................................................................................................................................. 4 Flask ................................................................................................................................................................. 4 Web2py ........................................................................................................................................................... 5 Pyramid............................................................................................................................................................ 6 Dash ................................................................................................................................................................. 7 3. Python Web Development Libraries – Django Framework ........................................................................ 9 Why should you use Django? .......................................................................................................................... 9 Who’s Using Django? ..................................................................................................................................... 11 Installing and Creating a Django project and app ......................................................................................... 15 Creating Django Project ................................................................................................................................. 16 Configuring Django ........................................................................................................................................ 17 Setting the settings ........................................................................................................................................ 18 Setting up a Database .................................................................................................................................... 19 Starting the Web Server ................................................................................................................................ 20 Django Models ............................................................................................................................................... 21 Creating an application .................................................................................................................................. 22 Creating a blog post model............................................................................................................................ 23 Creating tables for models in your database................................................................................................. 25 iii Python Web Development Libraries Django Admin ................................................................................................................................................ 25 4. Python Web Development Libraries – Flask Framework ......................................................................... 28 Flask Startup and Configuration .................................................................................................................... 28 Creating an app with flask ............................................................................................................................. 28 Creating URL Routing ..................................................................................................................................... 29 5. Python Web Development Libraries – Web2py Framework .................................................................... 36 Installing and Configuring Web2py Framework ............................................................................................ 36 Creating an app using Web2py ...................................................................................................................... 38 Deploying the app on cloud platform ............................................................................................................ 40 6. Python Web Development Libraries – Pyramid Framework .................................................................... 42 Installing, starting up and configuring ........................................................................................................... 42 Core Concepts ............................................................................................................................................... 43 Configuration ................................................................................................................................................. 43 URL generation .............................................................................................................................................. 43 Views ............................................................................................................................................................. 44 Extensibility ................................................................................................................................................... 44 Running a Hello, Pyramid Program................................................................................................................ 44 7. Python Web Development Libraries – Dash Framework ......................................................................... 47 Dash Setup ..................................................................................................................................................... 47 Dash or App Layout ....................................................................................................................................... 47 Core Components .......................................................................................................................................... 47 Writing Simple Dash app ............................................................................................................................... 48 Running the Dash app ..................................................................................................................................