3. Add new applications to the project¶
In this section, we’ll assume your project is already running() and that you are in your own shell, not at thebash
prompt in a container.
The simplest way to add a new Django application to a project is by placing itin the project directory, so it’s on the Python path. We’ll use a version ofthe Polls application that’s part ofthe Django tutorial.
Download the application (tip: open a second terminal shell so you can leavethe project running):
Note
The URL above requires that you have .
Otherwise, use https://github.com/divio/django-polls.git
.
And put the inner polls
application directory at the root of your project(you can do this with: mv django-polls/polls .
).
Edit settings.py
to include the application:
- "polls",
- ])
This settings.py
already includes INSTALLED_APPS
that have beenconfigured by applications in the project - here we are simply extending itwith new ones.
3.2.2. Configure URLs¶
Edit urls.py
to add the URLconf for the polls
application:
- urlpatterns = [
- url(r'^polls/', include('polls.urls', namespace='polls')),
- ] + aldryn_addons.urls.patterns() + i18n_patterns(
- # add your own i18n patterns here
- *aldryn_addons.urls.i18n_patterns() # MUST be the last entry!
- docker-compose run web python manage.py migrate
You will see the migrations being applied:
- Running migrations:
- Rendering model states... DONE
- Applying polls.0001_initial... OK
And when that has completed, open the project again in your browser:
You should see the new polls application in the admin:
3.4.1. Push your changes¶
If it works locally it should work on the Cloud, so let’s push the changes tothe Test server and deploy there.
First, add the change:
- git add settings.py urls.py polls
Commit them:
- git commit -m "Added polls application"
And push to the Divio Cloud Git server:
- git push origin develop
Note
The Control Panel will display your undeployed commits, and even a difffor each one.
And check the site on the Test server:
- divio project push db
(You’ll need to redeploy to see the results.)
Often, you want to add a reusable, pip-installable application. For thisexample, we’ll use ,a simple package that keeps access logs (and failed login attempts) for a site.
3.5.1. Add the package¶
Add django-axes==2.3.2
(it’s always sensible to specify a version number inrequirements) to the project’s :
- # <INSTALLED_ADDONS> # Warning: text inside the INSTALLED_ADDONS tags is auto-generated. Manual changes will be overwritten.
- [...]
- # </INSTALLED_ADDONS>
- django-axes==2.3.2
(Make sure that it’s outside the automatically generated #
section.)
<INSTALLED_ADDONS>
3.5.2. Rebuild the project¶
The project now needs to be rebuilt, so that Django Axes is installed:
- docker-compose build web
In the settings.py
, add axes
to INSTALLED_APPS
:
- INSTALLED_APPS.extend([
- "polls",
- "axes",
- ])
(Note that this application doesn’t need an entry in urls.py
, because itonly uses the admin).
3.5.4. Run migrations¶
Now the database needs to be migrated once again for the new application:
Check that it has installed as expected (Django Axes will show its records inthe admin).
3.5.5. Deploy to the Cloud¶
To deploy this to the Test server, push your changes, and deploy once more:
- git add settings.py requirements.in
- git commit -m "Added Django Axes"
- git push origin develop
- divio project deploy test