Python Programming Blueprints
eBook - ePub

Python Programming Blueprints

Daniel Furtado, Marcus Pennington

Share book
  1. English
  2. ePUB (mobile friendly)
  3. Available on iOS & Android
eBook - ePub

Python Programming Blueprints

Daniel Furtado, Marcus Pennington

Book details
Book preview
Table of contents
Citations

About This Book

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.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Python Programming Blueprints an online PDF/ePUB?
Yes, you can access Python Programming Blueprints by Daniel Furtado, Marcus Pennington in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in Python. We have over one million books available in our catalogue for you to explore.

Information

Year
2018
ISBN
9781786464903
Edition
1

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 internet—especially eBay—buying 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 ...

Table of contents