@@ -25,6 +25,70 @@ To use a database, you should choose an Add-on from [the Data Storage category][
25
25
## Email
26
26
You can't use a local SMTP server, instead choose one of our [ email Add-ons] [ messaging-addons ] .
27
27
28
+ ## Serving Static Files
29
+
30
+ Since there is no webserver , i.e. Apache or Nginx running inside the container
31
+ to serve the static files. We recommend to use[ dj-static] [ dj-static ] or [ whitenoise] [ whitenoise ] in combination with a WSGI
32
+ server like Gunicorn. Another approach is using a CDN, e.g. Amazon S3 to serve static files for
33
+ your application with [ django-storage] [ django-storage ] .
34
+ For further details, checkout the official package documentations.
35
+
36
+ The following code snippets showing how to use dj-static or whitenoise:
37
+
38
+ ### dj-static
39
+
40
+ - Add the following line to the requirement.txt:
41
+
42
+ ~~~ python
43
+ dj- static== 0.0 .6
44
+ ~~~
45
+
46
+ - Modify your settings.py:
47
+
48
+ ~~~ python
49
+ STATIC_ROOT = ' staticfiles'
50
+ STATIC_URL = ' /static/'
51
+ ~~~
52
+
53
+ - Update your wsgi.py with the following line:
54
+
55
+ ~~~ python
56
+ from django.core.wsgi import get_wsgi_application
57
+ from dj_static import Cling
58
+
59
+ application = Cling(get_wsgi_application())
60
+ ~~~
61
+
62
+ Please make sure that your files getting served properly, by adding an empty
63
+ dummy text file in the static folder of your repository, for testing purposes.
64
+
65
+
66
+ ### whitenoise
67
+
68
+ - Add the following line to the requirement.txt:
69
+
70
+ ~~~ python
71
+ whitenoise== 2.0 .3
72
+ ~~~
73
+
74
+ - Modify your settings.py:
75
+
76
+ ~~~ python
77
+ STATICFILES_STORAGE = ' whitenoise.django.GzipManifestStaticFilesStorage'
78
+ ~~~
79
+
80
+ - Update your wsgi.py with the following line:
81
+
82
+ ~~~ python
83
+ from django.core.wsgi import get_wsgi_application
84
+ from whitenoise.django import DjangoWhiteNoise
85
+
86
+ application = get_wsgi_application()
87
+ application = DjangoWhiteNoise(application)
88
+ ~~~
89
+
90
+
91
+
28
92
[ SSH-session ] : https://www.cloudcontrol.com/dev-center/platform-documentation#secure-shell-(ssh)
29
93
[ python buildpack ] : https://github.com/cloudControl/buildpack-python
30
94
[ pip ] : http://www.pip-installer.org/
@@ -34,3 +98,6 @@ You can't use a local SMTP server, instead choose one of our [email Add-ons][mes
34
98
[ add-on-credentials ] : https://www.cloudcontrol.com/dev-center/guides/python/add-on-credentials
35
99
[ cloudControl ] : https://www.cloudcontrol.com/
36
100
[ worker ] : https://www.cloudcontrol.com/dev-center/platform-documentation#scheduled-jobs-and-background-workers
101
+ [ dj-static ] : https://github.com/kennethreitz/dj-static
102
+ [ whitenoise ] : https://warehouse.python.org/project/whitenoise/
103
+ [ django-storage ] : https://django-storages.readthedocs.org/en/latest/
0 commit comments