Python Programming Blueprints
eBook - ePub

Python Programming Blueprints

Daniel Furtado, Marcus Pennington

Buch teilen
  1. English
  2. ePUB (handyfreundlich)
  3. Über iOS und Android verfügbar
eBook - ePub

Python Programming Blueprints

Daniel Furtado, Marcus Pennington

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

How to build useful, real-world applications in the Python programming languageAbout This Book• Deliver scalable and high-performing applications in Python.• Delve into the great ecosystem of Python frameworks and libraries through projects that you will build with this book.• This comprehensive guide will help you demonstrate the power of Python by building practical projects.Who This Book Is ForThis book is for software developers who are familiar with Python and want to gain hands-on experience with web and software development projects. A basic knowledge of Python programming is required.What You Will Learn• Learn object-oriented and functional programming concepts while developing projects• The dos and don'ts of storing passwords in a database• Develop a fully functional website using the popular Django framework• Use the Beautiful Soup library to perform web scrapping• Get started with cloud computing by building microservice and serverless applications in AWS• Develop scalable and cohesive microservices using the Nameko framework• Create service dependencies for Redis and PostgreSQLIn DetailPython is a very powerful, high-level, object-oriented programming language. It's known for its simplicity and huge community support. Python Programming Blueprints will help you build useful, real-world applications using Python.In this book, we will cover some of the most common tasks that Python developers face on a daily basis, including performance optimization and making web applications more secure. We will familiarize ourselves with the associated software stack and master asynchronous features in Python. We will build a weather application using command-line parsing. We will then move on to create a Spotify remote control where we'll use OAuth and the Spotify Web API. The next project will cover reactive extensions by teaching you how to cast votes on Twitter the Python way. We will also focus on web development by using the famous Django framework to create an online game store. We will then create a web-based messenger using the new Nameko microservice framework. We will cover topics like authenticating users and, storing messages in Redis.By the end of the book, you will have gained hands-on experience in coding with Python.Style and approachWith a hands-on approach, Python Programming Blueprints guides you through diverse real-life projects to get you started; it presents most aspects of the Python programming language gradually, going from basic to advanced topics.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Python Programming Blueprints als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Python Programming Blueprints von Daniel Furtado, Marcus Pennington im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Informatique & Programmation en Python. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2018
ISBN
9781786464903

Online Video Game Store with Django

I was born in the late seventies, which means that I grew up during the birth of the video game industry. My first video game console was the Atari 2600, and it was because of that specific video game console that I decided that I wanted to be a programmer and make video games. I never got a job within the gaming industry, however, but I still love playing video games, and in, my spare time, I try to develop my own games.
To this day, I still go around the internetespecially eBaybuying old video games to bring back my nice childhood memories when all the family, my parents, and my sister, used to play Atari 2600 games together.
Because of my interest in vintage video games, we are going to develop a vintage video game online store; this will be a great way to develop something fun and also learn a lot about web development with the popular Django web framework.
In this chapter, we will cover the following:
  • Setting up the environment
  • Creating a Django project
  • Creating Django apps
  • Exploring the Django admin interface
  • Learning how to create an application model and perform queries with the Django ORM
Also, as an extra, we will be using the npm (Node Package Manager) to download the client-side dependencies. We will also cover how to create simple tasks using the task runner Gulp.
To make our application prettier without a lot of effort, we are going to use Bootstrap.
So, let's get started!

Setting up the development environment

As usual, we are going to start setting up the environment for development. In Chapter 4, Exchange Rates and the Currency Conversion Tool, you were introduced to pipenv, so in this and the following chapters, we are going to be using pipenv to create our virtual environment and manage our dependencies.
First, we want to create the directory where we are going to keep our project. In your working directory, create a directory called django-project as follows:
mkdir django-project && cd django-project
Now we can run pipenv to create our virtual environment:
pipenv --three
If you have Python 3 installed in another location, you can use the argument --python and specify the path where the Python executable is located. If everything went fine, you should see an output such as the following:
Now we can activate our virtual environment using the pipenv command shell:
pipenv shell
Great! The only dependency that we are going to add for now is Django.
At the time of writing this book, Django 2.0 had been released. It has really nice features compared to its predecessor. You can see the list of new features at https://docs.djangoproject.com/en/2.0/releases/2.0/.
Let's install Django in our virtual environment:
pipenv install django
Django 2.0 has dropped support for Python 2.0, so if you are planning to develop an application using Python 2, you should install Django 1.11.x or lower. I strongly recommend that you start a new project using Python 3. Python 2 will stop being maintained after a couple of years, and new packages will be created for Python 3. Popular packages of Python 2 will migrate to Python 3.
In my opinion, the best new feature of Django 2 is the new routing syntax, because now it is not necessary to write regular expressions. It is much cleaner and more readable to write something like the following:
path('user/<int:id>/', views.get_user_by_id)
The previous syntax relied more on regular expressions:
url('^user/?P<id>[0-9]/$', views.get_user_by_id)
It is much simpler this way. Another feature that I really like in Django 2.0 is that they have improved the admin UI a little bit and made it responsive; this is a great feature, because I have experienced that creating a new user (while you are on the go with no access to a desktop) on a non-responsive site on a small mobile phone screen can be painful.

Installing Node.js

When it comes to web development, it is almost impossible to stay away from Node.js. Node.js is a project that was released back in 2009. It is a JavaScript runtime that allows us to run JavaScript on the server-side. Why do we care about Node.js if we are developing a website using Django and Python? The reason is that the Node.js ecosystem has several tools that will help us to manage the client-side dependencies in a simple manner. One of these tools that we are going to use is the npm.
Think about npm as the pip of the JavaScript world. npm, however, has many more features. One of the features that we are going to use is npm scripts.
So, let's go ahead and install Node.js. Usually, developers need to go over to the Node.js website and download it from there, but I find it much simpler to use a tool called NVM, which allows us to install and switch easily between different versions of Node.js.
To install NVM in our environment, you can follow the instructions at https://github.com/creationix/nvm.
We are covering installation of NVM on Unix/Linux and macOS systems. If you are using Windows, there's an awesome version for Windows that has been developed in the Go language; it can be found at https://github.com/coreybutler/nvm-windows.
When NVM is installed, you are ready to install the latest version of Node.js with the following command:
nvm install node
You can verify if the installation is correct with the command:
node --version
While writing this book, the latest Node.js version is v8.8.1.
You can also type npm on the terminal, where you should see an output similar to the output that follows:

Creating a new Django project

To create a new Django project, run the following command:
django-admin startproject gamestore
Note that ...

Inhaltsverzeichnis