Develop standalone Django apps to serve as the reusable building blocks for larger Django projects. This book explores best practices for publishing these apps, with special considerations for testing Django apps, and strategies for extracting existing functionality into a separate package. This jumpstart reference is divided into four distinct and sequential sections, all containing short, engaging chapters that can be read in a modular fashion, depending on your level of experience. The first section covers the structure and scope of standalone Django apps. The second section digs into questions about pulling code out of existing projects and into new standalone apps for reuse. The third section details additional, advanced technical best practices toward making standalone apps as broadly useful as possible. The fourth and final section covers strategies for managing a published Django app. Django Standalone Apps is the perfect resource for developers who have at least some prior experience working with Django web applications and want to simplify their deployments and share their knowledge as open source packages. What You'll Learn Scope a standalone Django app project for optimum usefulness Extract code from existing projects to reuse Test a standalone app outside of your Django project Reuse your own code for increased delivery cadence and code quality Review best practices for maintaining a Django app package Who This Book Is For Professional developers who work with Django. Deep expertise is not required or expected, but readers should have working familiarity with Django.
Author(s): Ben Lopatin
Publisher: Apress
Year: 2020
Language: English
Pages: 169
Table of Contents
About the Author
About the Technical Reviewer
Introduction
Part I: Basic Components of a Django App
Chapter 1: Defining the scope of a Django standalone app
Benefits of creating standalone apps
Sharing your work
Improved code quality
Don’t repeat yourself
Commonality across a company
Commonalities across client projects
The currency of prestige
With or without Django?
Choosing your dependencies
Necessary functionality
Version compatibility
Testing and documentation
Maintenance cadence
Specific vs. generalized
Summary
Chapter 2: Structuring standalone Django apps
Django apps as Python modules
What about middleware and URLs and views?
Example app: currency
Summary
Chapter 3: Testing
Why test?
Testing apps from a Django project
Testing the app
Testing outside of a project
Using a testing script
Testing application relationships
Where to include tests
Testing without Django
Summary
Chapter 4: Model migrations
Migrations outside of a project
Testing migrations
Additional migration guidelines
Summary
Chapter 5: Templates
Three basic strategies
What to include
Email and miscellaneous templates
Summary
Chapter 6: Using static files
Static files in standalone apps
In the Django admin
Summary
Chapter 7: Namespacing in your app
Namespaces at a glance
App itself
URLs
Settings
Management commands
Template tags
Models and database tables
Chapter 8: Creating a basic package
An example blog app
A basic setup.py file
Adding templates and static files
Installing and using
Summary
Part II: Scoping and Extracting a Reusable App
Chapter 9: Scoping and drawing boundaries
Scoping and the nature of the problem
The job of a standalone app
The dimensions for creation and extraction
Sizing the scope of an app
When an app is too big
When an app is too small
Summary
Chapter 10: Separating your app
Getting started
Refactor first
Model renaming and migrations
Allowing customization
Backend classes
Signals
Finalization and removing from the project
Summary
Chapter 11: Adding your app back in
Verifying locally
Source control–based packages
Published packaged
Summary
Part III: Beyond the Basics
Chapter 12: Handling app settings
Settings naming
Settings formats
Sourcing app settings
Summary
Chapter 13: Internationalization
Why translation
Translatable strings and how translation works
Prioritizing translation steps
Model content and translations
Summary
Chapter 14: Managing version compatibility
Python version
Django and dependencies
Solving for incompatibilities
Future proofing
Summary
Chapter 15: Mixed dependency support
Beyond Django
The nuts and bolts
Real-world examples
Summary
Chapter 16: Modularity
Additional standalone apps
Using sub-apps
Embracing horizontal modularity
Summary
Chapter 17: Better packaging
Version consolidation
Using a source directory
Using setup.cfg
The pyproject.toml and more tooling
Summary
Part IV: Managing Your Standalone App
Chapter 18: Licensing
What licenses do
Varieties of licenses
How and where to include your license
How to include other licenses
Summary
Chapter 19: Documenting your standalone app
Starting with questions
The forms of documentation
Code comments and docstrings
Tools for documentation
Summary
Chapter 20: Additional Testing
Testing migrations
Testing against different versions
Using pytest
Summary
Chapter 21: Automating
What is it and why bother?
Starting to automate
Continuous integration services
Travis CI
GitHub
GitLab
CircleCI
Others
Summary
Chapter 22: Databases and other backend-specific considerations
Backend-specific implementation and features
Approaching database-specific functionality
Summary
Chapter 23: Collaborating
Why contributions
What to expect
Setting expectations
The role and obligations of an open source maintainer
Summary
Chapter 24: Using app templates
startapp
Cookiecutter
Summary
Index