Book Image

Python 3 Web Development Beginner's Guide

By : Michel Anders
Book Image

Python 3 Web Development Beginner's Guide

By: Michel Anders

Overview of this book

<p>Building your own Python web applications provides you with the opportunity to have great functionality, with no restrictions. However, creating web applications with Python is not straightforward. Coupled with learning a new skill of developing web applications, you would normally have to learn how to work with a framework as well.</p> <p><em>Python 3 Web Development Beginner's Guide</em> shows you how to independently build your own web application that is easy to use, performs smoothly, and is themed to your taste – all without having to learn another web framework.</p> <p>Web development can take time and is often fiddly to get right. This book will show you how to design and implement a complex program from start to finish. Each chapter looks at a different type of web application, meaning that you will learn about a wide variety of features and how to add them to your custom web application. You will also learn to implement jQuery into your web application to give it extra functionality. By using the right combination of a wide range of tools, you can have a fully functional, complex web application up and running in no time.</p>
Table of Contents (19 chapters)
Python 3 Web Development Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – using the Entity class


Let us first define for ourselves how we want to use an Entity class, because the interface we create must match as closely as possible the things we would like to express in our code. The following example shows what we have in mind (available as carexample.py):

Chapter5/carexample.py

from entity import Entity

class Car(Entity): pass

Car.threadinit('c:/tmp/cardatabase.db')
Car.inittable(make="",model="",licenseplate="unique")

mycar = Car(make="Volvo",model="C30",licenseplate="12-abc-3")
yourcar = Car(make="Renault",model="Twingo",licenseplate="ab-cd-12")

allcars = Car.list()

for id in allcars:
	car=Car(id=id)
	print(car.make, car.model, car.licenseplate)

The idea is to create a Car class that is a subclass of Entity. We therefore have to take the following steps:

  1. Import the Entity class from the entity module.

  2. Define the Car class. The body of this class is completely empty as we simply inherit all functionality from the Entity class. We could...