Skip to content

Commit 426f5fa

Browse files
authored
Merge pull request #203 from realpython/django-hosting-heroku
Django hosting heroku
2 parents d3876db + 0e52334 commit 426f5fa

File tree

51 files changed

+2345
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2345
-1
lines changed

complex-numbers/bermuda.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@
356356
"name": "python",
357357
"nbconvert_exporter": "python",
358358
"pygments_lexer": "ipython3",
359-
"version": "3.9.2"
359+
"version": "3.9.5"
360360
}
361361
},
362362
"nbformat": 4,

django-hosting-heroku/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Hosting a Django Project on Heroku
2+
3+
This is a companion project to a Real Python tutorial about [Hosting a Django Project on Heroku](https://realpython.com/django-hosting-on-heroku/). It's a bare-bones Django project without any views.
4+
5+
## Instructions
6+
7+
You should follow the step-by-step instructions in the tutorial to deploy this project to Heroku. Alternatively, you can run the finished project by following the instructions below.
8+
9+
Download the code by cloning the `materials` repository:
10+
11+
```shell
12+
$ git clone https://github.com/realpython/materials.git
13+
```
14+
15+
Create a new local Git repository:
16+
17+
```shell
18+
$ cd materials/django-hosting-heroku/source_code_final/portfolio-project
19+
$ git init
20+
$ git add .
21+
$ git commit -m "Initial commit"
22+
```
23+
24+
Deploy the code to Heroku:
25+
26+
```shell
27+
$ heroku login
28+
$ heroku create
29+
$ heroku config:set DEBUG=True SECRET_KEY=$(head -c 32 /dev/urandom | base64)
30+
$ git push heroku master
31+
$ heroku open
32+
```
33+
34+
Optionally, for local development:
35+
36+
```shell
37+
$ python3 -m venv ./venv --prompt portfolio
38+
$ source venv/bin/activate
39+
(portfolio) $ python -m pip install -r requirements.txt
40+
(portfolio) $ python -m pip install --upgrade pip
41+
(portfolio) $ heroku config --shell > .env
42+
(portfolio) $ heroku local
43+
```
44+
45+
Navigate your web browser to <http://0.0.0.0:5000/>
46+
47+
**Note:** If you're on a Mac, then you may run into issues with the `heroku local` command above. To mitigate it, try commenting out the line with your `DATABASE_URL` variable from the `.env` file. Alternatively, you can uninstall the `psycopg2` driver and install its binary counterpart:
48+
49+
```console
50+
$ pip uninstall psycopg2
51+
$ pip install psycopg2-binary
52+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SECRET_KEY=6aj9il2xu2vqwvnitsg@!+4-8t3%zwr@$agm7x%o%yb2t9ivt%
Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/python,pycharm+all,django
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=python,pycharm+all,django
4+
5+
### Django ###
6+
*.log
7+
*.pot
8+
*.pyc
9+
__pycache__/
10+
local_settings.py
11+
db.sqlite3
12+
db.sqlite3-journal
13+
media
14+
15+
# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
16+
# in your Git repository. Update and uncomment the following line accordingly.
17+
# <django-project-name>/staticfiles/
18+
19+
### Django.Python Stack ###
20+
# Byte-compiled / optimized / DLL files
21+
*.py[cod]
22+
*$py.class
23+
24+
# C extensions
25+
*.so
26+
27+
# Distribution / packaging
28+
.Python
29+
build/
30+
develop-eggs/
31+
dist/
32+
downloads/
33+
eggs/
34+
.eggs/
35+
lib/
36+
lib64/
37+
parts/
38+
sdist/
39+
var/
40+
wheels/
41+
share/python-wheels/
42+
*.egg-info/
43+
.installed.cfg
44+
*.egg
45+
MANIFEST
46+
47+
# PyInstaller
48+
# Usually these files are written by a python script from a template
49+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
50+
*.manifest
51+
*.spec
52+
53+
# Installer logs
54+
pip-log.txt
55+
pip-delete-this-directory.txt
56+
57+
# Unit test / coverage reports
58+
htmlcov/
59+
.tox/
60+
.nox/
61+
.coverage
62+
.coverage.*
63+
.cache
64+
nosetests.xml
65+
coverage.xml
66+
*.cover
67+
*.py,cover
68+
.hypothesis/
69+
.pytest_cache/
70+
cover/
71+
72+
# Translations
73+
*.mo
74+
75+
# Django stuff:
76+
77+
# Flask stuff:
78+
instance/
79+
.webassets-cache
80+
81+
# Scrapy stuff:
82+
.scrapy
83+
84+
# Sphinx documentation
85+
docs/_build/
86+
87+
# PyBuilder
88+
.pybuilder/
89+
target/
90+
91+
# Jupyter Notebook
92+
.ipynb_checkpoints
93+
94+
# IPython
95+
profile_default/
96+
ipython_config.py
97+
98+
# pyenv
99+
# For a library or package, you might want to ignore these files since the code is
100+
# intended to run in multiple environments; otherwise, check them in:
101+
# .python-version
102+
103+
# pipenv
104+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
105+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
106+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
107+
# install all needed dependencies.
108+
#Pipfile.lock
109+
110+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
111+
__pypackages__/
112+
113+
# Celery stuff
114+
celerybeat-schedule
115+
celerybeat.pid
116+
117+
# SageMath parsed files
118+
*.sage.py
119+
120+
# Environments
121+
.env
122+
.venv
123+
env/
124+
venv/
125+
ENV/
126+
env.bak/
127+
venv.bak/
128+
129+
# Spyder project settings
130+
.spyderproject
131+
.spyproject
132+
133+
# Rope project settings
134+
.ropeproject
135+
136+
# mkdocs documentation
137+
/site
138+
139+
# mypy
140+
.mypy_cache/
141+
.dmypy.json
142+
dmypy.json
143+
144+
# Pyre type checker
145+
.pyre/
146+
147+
# pytype static type analyzer
148+
.pytype/
149+
150+
# Cython debug symbols
151+
cython_debug/
152+
153+
### PyCharm+all ###
154+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
155+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
156+
157+
# User-specific stuff
158+
.idea/**/workspace.xml
159+
.idea/**/tasks.xml
160+
.idea/**/usage.statistics.xml
161+
.idea/**/dictionaries
162+
.idea/**/shelf
163+
164+
# AWS User-specific
165+
.idea/**/aws.xml
166+
167+
# Generated files
168+
.idea/**/contentModel.xml
169+
170+
# Sensitive or high-churn files
171+
.idea/**/dataSources/
172+
.idea/**/dataSources.ids
173+
.idea/**/dataSources.local.xml
174+
.idea/**/sqlDataSources.xml
175+
.idea/**/dynamic.xml
176+
.idea/**/uiDesigner.xml
177+
.idea/**/dbnavigator.xml
178+
179+
# Gradle
180+
.idea/**/gradle.xml
181+
.idea/**/libraries
182+
183+
# Gradle and Maven with auto-import
184+
# When using Gradle or Maven with auto-import, you should exclude module files,
185+
# since they will be recreated, and may cause churn. Uncomment if using
186+
# auto-import.
187+
# .idea/artifacts
188+
# .idea/compiler.xml
189+
# .idea/jarRepositories.xml
190+
# .idea/modules.xml
191+
# .idea/*.iml
192+
# .idea/modules
193+
# *.iml
194+
# *.ipr
195+
196+
# CMake
197+
cmake-build-*/
198+
199+
# Mongo Explorer plugin
200+
.idea/**/mongoSettings.xml
201+
202+
# File-based project format
203+
*.iws
204+
205+
# IntelliJ
206+
out/
207+
208+
# mpeltonen/sbt-idea plugin
209+
.idea_modules/
210+
211+
# JIRA plugin
212+
atlassian-ide-plugin.xml
213+
214+
# Cursive Clojure plugin
215+
.idea/replstate.xml
216+
217+
# Crashlytics plugin (for Android Studio and IntelliJ)
218+
com_crashlytics_export_strings.xml
219+
crashlytics.properties
220+
crashlytics-build.properties
221+
fabric.properties
222+
223+
# Editor-based Rest Client
224+
.idea/httpRequests
225+
226+
# Android studio 3.1+ serialized cache file
227+
.idea/caches/build_file_checksums.ser
228+
229+
### PyCharm+all Patch ###
230+
# Ignores the whole .idea folder and all .iml files
231+
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
232+
233+
.idea/
234+
235+
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
236+
237+
*.iml
238+
modules.xml
239+
.idea/misc.xml
240+
*.ipr
241+
242+
# Sonarlint plugin
243+
.idea/sonarlint
244+
245+
### Python ###
246+
# Byte-compiled / optimized / DLL files
247+
248+
# C extensions
249+
250+
# Distribution / packaging
251+
252+
# PyInstaller
253+
# Usually these files are written by a python script from a template
254+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
255+
256+
# Installer logs
257+
258+
# Unit test / coverage reports
259+
260+
# Translations
261+
262+
# Django stuff:
263+
264+
# Flask stuff:
265+
266+
# Scrapy stuff:
267+
268+
# Sphinx documentation
269+
270+
# PyBuilder
271+
272+
# Jupyter Notebook
273+
274+
# IPython
275+
276+
# pyenv
277+
# For a library or package, you might want to ignore these files since the code is
278+
# intended to run in multiple environments; otherwise, check them in:
279+
# .python-version
280+
281+
# pipenv
282+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
283+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
284+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
285+
# install all needed dependencies.
286+
287+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
288+
289+
# Celery stuff
290+
291+
# SageMath parsed files
292+
293+
# Environments
294+
295+
# Spyder project settings
296+
297+
# Rope project settings
298+
299+
# mkdocs documentation
300+
301+
# mypy
302+
303+
# Pyre type checker
304+
305+
# pytype static type analyzer
306+
307+
# Cython debug symbols
308+
309+
# End of https://www.toptal.com/developers/gitignore/api/python,pycharm+all,django
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
web: python manage.py runserver 0.0.0.0:$PORT
2+
release: python manage.py migrate
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "portfolio.settings")
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == "__main__":
22+
main()

django-hosting-heroku/source_code_final/portfolio-project/portfolio/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)