Ben Lopatin
New York, NY, USA
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the books product page, located at www.apress.com/978-1-4842-5631-2 . For more detailed information, please visit http://www.apress.com/source-code .
ISBN 978-1-4842-5631-2 e-ISBN 978-1-4842-5632-9
https://doi.org/10.1007/978-1-4842-5632-9
Ben Lopatin 2020
Apress Standard
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.
The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
Introduction
At 15 years old, the Django web framework is arguably the most popular Python web framework today and one of the most successful open source Python projects ever. Many things and people have contributed to this, and one of them is the architecture of the framework. Django sites, or projects, are made up of several to many "apps," packages that may include everything from database models to forms and HTTP views required to support one particular part of the project. Not only do apps help organize larger web projects, they also make it possible to reuse that functionality by reusing apps across other projects as their own installable Python packages: Django standalone apps.
This book is for Django developers who are either new to writing their own standalone apps or who have written them before but are looking for some common guidance. You dont need to be a Django guru-ninja-wizard-whatever to write standalone apps, but you will need at least moderate familiarity with Django to use this book.
This book is for developers in two categories:
You have been working with Django for at least a little while and would like to create a standalone app.
You have written at least one Django standalone app already but there are aspects of creating another or managing your app, from process to corner cases, that youre unsure of.
The book is roughly grouped into four parts.
The first part is geared toward the developer who has not yet written a standalone app and maybe who finds the idea of putting together, and publishing, a Python package a bit daunting (its not!). What well cover in this part is designed to be enough to get you started with a basic but working and publishable standalone app. In the first eight chapters, youll learn how to structure a standalone app, manage features like templates and migrations, and create a separate installable package.
The second part is a little bit more strategic. Here were concerned with the concepts around pulling standalone apps out from existing projects. In this situation you seemingly have an advantage since you already have working code written; however, if you want to extract for reuse, you have to identify where to draw the line between likely coupled code in your own project. More challenging is the prospect of not just making a reusable app based on your code, but replacing your original code with your new standalone app. This part deals with those questions, decisions, and some strategies for these real-world situations.
The third part carries forward the topics in Part 1 including how to work through further issues. How do you best deal with app-specific configuration? How can you support multiple versions of Django or Python? Some of the topics here overlap with issues youll face in any Django project; however, the details of implementing them, and implementing them well in a standalone app, pose different challenges. This is when youll need to start considering scenarios beyond your own immediate use case, those things you havent yet had to worry about in your own projects. If the goal of creating a reusable app is to streamline and simplify the process of building Django websites, then here we want to streamline and simplify the process of building and maintaining reusable apps themselves.
The fourth part is about managing a Django standalone app in the wild. How do you ensure you have a good release every time? Whats the best way of ensuring a Django versioncompatible pipeline? While there is overlap here with managing any software package, Python or otherwise, well focus especially on issues and solutions to Django apps.