Editing
Refactoring a Django App as a Stand-Alone Module
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
[[Category:Django]] [[Category:Web Development]] == Overview == This page catalogs the workflow involved in taking an app that is part of a Django project and refactoring it as a stand-alone module. [[Reusable Django Packages/Apps]] contains an overview of the principles of creating stand-alone Django modules == Workflow == === App set up === * Move project files to directory outside Django project, e.g. `~/develop/django/apps` <syntaxhighlight lang="text"> - project_root_dir |-- app_dir | |-- tests/ | |-- __init__.py | |-- admin.py | |-- app.py | `-- models.py |-- .gitignore |-- LICENSE |-- MANIFEST.IN |-- README.md `-- setup.py </syntaxhighlight> === Configure app files === * Add package config files ** `LICENSE` ** `MANIFEST.in` ** `README.md` ** `setup.py` * Delete `migrations` directory * Add project properties in the app directory ** `__init__.py` *** `__author__` *** `__version__` *** `default_app_config = 'app_name.apps.AppNameConfig'` ** `apps.py` defines a class named `AppNameConfig` with the following properties: *** `name` - app token, e.g. the name of the directory containing the app *** `verbose_name` - Plain english description of the app * Consider moving views defined in the app out of the app and into the actual Django web applications that references the app. * N.B. that the Grappelli admin app does not handle models that are broken out into separate files. * Update `MANIFEST.in` to include any files that are not in the top level of the app directory. * Update `README.md` with information about installing, configuring, and using the app. * Update `setup.py` with configuration for creating distribution files out of the app. * Exclude Mac OS files. PyCharm project files, and distribution files in `.gitignore`. * Create a distribution for the app: `python setup.py sdist --formats=gztar,zip` === Configure Django project to use the stand-alone app === * Add app identifier to `INSTALLED_APPS` in `webapp/settings.py` * Add app distribution to `requirements.txt` * Incorporate database changes: ** `python manage.py makemigrations app_name` ** `python manage.py migrate app_name` === Distributing the app === * Upload the app's distribution files to the `nrose-django-packages` Amazon S3 bucket. * Create GitHub repo for the app and push code there.
Summary:
Please note that all contributions to Littledamien Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Littledamien Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information