@@ -212,7 +212,14 @@ Believe it or not, this pun didn't actually hit me until I was rewriting this ch
212
212
For 10 years it was right under my nose. I think that makes it funnier actually.]
213
213
files from Python.
214
214
215
- This is how we tell Django to enable it, in _settings.py_:
215
+ First we install whitenoise into our local environment:
216
+
217
+ [source,python]
218
+ ----
219
+ pip install whitenoise
220
+ ----
221
+
222
+ Then we tell Django to enable it, in _settings.py_:
216
223
217
224
[role="sourcecode"]
218
225
.src/superlists/settings.py (ch10l002)
@@ -260,9 +267,6 @@ Let's rerun our FTs to confirm:
260
267
// If we do that, however, we'll need to make sure readers rebuild the image each time
261
268
// we add a requirement - such as at this point.
262
269
263
-
264
- // JAN: That doesn't work until you install whitenoise to venv on local machine
265
-
266
270
[role="small-code"]
267
271
[subs="specialcharacters,macros"]
268
272
----
@@ -378,6 +382,7 @@ $ *git add requirements.txt*
378
382
$ *git commit -m "Add a requirements.txt with Django, gunicorn and whitenoise"*
379
383
----
380
384
385
+
381
386
You may be wondering why we didn't add our other dependency,
382
387
Selenium, to our requirements,
383
388
or why we didn't just add _all_ the dependencies,
@@ -447,7 +452,7 @@ TIP: Forgetting the `-r` and running `pip install requirements.txt`
447
452
// since it's related to the app being production ready).
448
453
// TODO yep let's definitely do this.
449
454
450
- Let's do a build & run & test to check everything still works:
455
+ Let's build & run:
451
456
452
457
[subs="specialcharacters,quotes"]
453
458
----
@@ -457,6 +462,18 @@ $ *docker build -t superlists . && docker run \
457
462
-it superlists*
458
463
----
459
464
465
+ And then test to check everything still works:
466
+
467
+ [role="small-code"]
468
+ [subs="specialcharacters,macros"]
469
+ ----
470
+ $ pass:quotes[*TEST_SERVER=localhost:8888 python src/manage.py test functional_tests \
471
+ --failfast*]
472
+ [...]
473
+
474
+ OK
475
+ ----
476
+
460
477
=== Using Environment Variables to Adjust Settings for Production
461
478
462
479
((("DEBUG settings")))
@@ -495,9 +512,10 @@ Environment variables also have the advantage of working for non-Django stuff to
495
512
There are lots of ways you might do this.
496
513
497
514
Here's what I propose; it may seem a little fiddly,
498
- but I'll provide a little justification for each choice.
515
+ but I'll provide a little justification for each choice.
499
516
Let them be an inspiration (but not a template) for your own choices!
500
517
518
+ Note that this if statement replaces the DEBUG and SECRET_KEY lines that are included by default in the settings.py file:
501
519
502
520
[role="sourcecode"]
503
521
.superlists/settings.py (ch10l006)
@@ -745,7 +763,15 @@ CMD gunicorn --bind :8888 superlists.wsgi:application
745
763
746
764
// TODO: gitignore src/static
747
765
748
- Well, it was fiddly, but that should get us to passing tests!
766
+ Well, it was fiddly, but that should get us to passing tests after we build & run the docker container!
767
+
768
+ [subs="specialcharacters,quotes"]
769
+ ----
770
+ $ *docker build -t superlists . && docker run \
771
+ -p 8888:8888 \
772
+ --mount type=bind,source=./src/db.sqlite3,target=/src/db.sqlite3 \
773
+ -it superlists*
774
+ ----
749
775
750
776
751
777
[role="small-code"]
@@ -861,7 +887,7 @@ If you're like me you might find yourself wondering if we really _did_ see them
861
887
and starting to doubt your own sanity.
862
888
But the explanation is that Django's
863
889
https://docs.djangoproject.com/en/4.2/ref/logging/#default-logging-configuration[default logging configuration]
864
- changes when DEBUG is turned off:
890
+ changes when DEBUG is turned off.
865
891
866
892
This means we need to interact with the standard library's `logging` module,
867
893
unfortunately one of the most fiddly parts of the Python standard libraryfootnote:[
@@ -873,7 +899,7 @@ but sometimes you just wanna say "just print stuff to stdout pls",
873
899
and you wish that configuring the simplest thing was a little easier.].
874
900
875
901
Here's pretty much the simplest possible logging config
876
- which just prints everything to the console (i.e. standard out).
902
+ which just prints everything to the console (i.e. standard out). I've added this code to the very end of the settings.py file.
877
903
878
904
879
905
[role="sourcecode"]
0 commit comments