A beginners guide to web development with Django 2.
This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and many iterations to get reader feedback, pivot until you have the right book and build traction once you do.
Overview
This book aims to provide you with a practical guide to web development using Django 2 and Python 3. The book is designed primarily for students, providing a walkthrough of the steps involved in getting a web application up and running with Django. However, anyone whos starting off with web development will find this book to be beneficial.
This book seeks to complement the official Django Tutorials and many of the other excellent tutorials available online. By putting everything together in one place, this book fills in many of the gaps in the official Django documentation by providing an example-based, design-driven approach to learning the Django framework. Furthermore, this book provides an introduction to many of the aspects required to master web application development (such as HTML, CSS and JavaScript).
1.1 Why Work with this Book?
This book will save you time. On many occasions weve seen clever students get stuck, spending hours trying to fight with Django and other aspects of web development. More often than not, the problem was usually because a key piece of information was not provided, or something was not made clear. While the occasional blip might set you back 10-15 minutes, sometimes they can take hours to resolve. Weve tried to remove as many of these hurdles as possible. This will mean you can get on with developing your application instead of getting stuck.
This book will lower the learning curve. Web application frameworks can save you a lot of hassle and a lot of time. But that is only true if you know how to use them in the first place! Often the learning curve is steep. This book tries to get you going and going fast by explaining how all the pieces fit together and how to build your web app logically.
This book will improve your workflow. Using web application frameworks requires you to pick up and run with particular design patterns so you only have to fill in certain pieces in certain places. After working with many students, we heard lots of complaints about using web application frameworks specifically about how they take control away from the software engineer (i.e. inversion of control). To help you, weve created several workflows to focus your development process so that you can regain that sense of control and build your web application in a disciplined manner.
This book is not designed to be read. Whatever you do, do not read this book! It is a hands-on guide to building web applications in Django. Reading is not doing. To increase the value you gain from this experience, go through and develop the application. When you code up the application, do not just cut and paste the code. Type it in, think about what it does, then read the explanations we have provided. If you still do not understand, then check out the Django documentation, go to !
1.2 What you will Learn
In this book, we will be taking an example-based approach to web application development. In the process, we will show you how to design a web application called Rango (), and take a step by step in setting up, developing and deploying the application. Along the way, well show you how to perform the following key tasks which are common to most software engineering and web-based projects.
- How to configure your development environment including how to use the terminal, your virtual environment, the
pip
installer, and how to work with Git. - How to set up a Django project and create a basic Django application.
- How to configure the Django project to serve static media and user-uploaded media files (such as profile images).
- How to work with Djangos Model-View-Template design pattern.
- How to work with database models and use the object-relational mapping (ORM) functionality provided by Django.
- How to create forms that can utilise your database models to create dynamically-generated webpages.
- How to use the user authentication services provided by Django.
- How to incorporate external services into your Django application.
- How to include Cascading Styling Sheets (CSS) and JavaScript within a web application to aid in styling and providing it with additional functionality.
- How to apply CSS to give your application a professional look and feel.
- How to work with cookies and sessions with Django.
- How to include more advanced functionality like AJAX into your application.
- How to write class-based views with Django.
- How to Deploy your application to a web server using PythonAnywhere.
At the end of each chapter, we have also included several exercises designed to push you to apply what you have learnt during the chapter. To push you harder, weve also included several open development challenges, which require you to use many of the lessons from the previous chapters but dont worry, as weve also included solutions and explanations on these, too!
Exercises
In each chapter, we have added several exercises to test your knowledge and skill. Such exercises are denoted like this.
You will need to complete all of these exercises as subsequent chapters will assume that you have fully completed them.
Hints and Tips
For each set of exercises, we will provide a series of hints and tips that will assist you if you need a push. If you get stuck however, you can always check out our solutions to all the exercises on our GitHub repository.
1.3 Technologies and Services
Through the course of this book, we will use various technologies and external services including:
- the Python programming language;
- the Pip package manager;
- Django;
- unit testing;
- the Git version control system;
- GitHub;
- HTML;
- CSS;
- the JavaScript programming language;
- the JQuery library;
- the Twitter Bootstrap framework;
- the Bing Search API; and
- the PythonAnywhere hosting service.
Weve selected all of these technologies and services as they are either fundamental to web development, and/or enable us to provide examples on how to integrate your web application with CSS toolkits like Twitter Bootstrap, external services like those provided by the Microsoft Bing Search API and deploy your application quickly and easily with