Skip to content

Commit 9ef676d

Browse files
author
Mario Colombo
committed
Merge branch 'main' into support/cms-4.0.x
2 parents c2ff347 + d682b11 commit 9ef676d

19 files changed

+93
-59
lines changed

.env-local

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
DATABASE_URL=postgres://postgres@database_default:5432/db
1+
DATABASE_URL=postgres://postgres:password@database_default:5432/db
22
DEFAULT_STORAGE_DSN=file:///data/media/?url=%2Fmedia%2F
3-
DJANGO_DEBUG=True
3+
DEBUG=True
44
DOMAIN_ALIASES=localhost, 127.0.0.1
55
SECURE_SSL_REDIRECT=False

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
db.sqlite3
55

66
# Django
7-
/staticfiles
7+
/staticfiles_collected/
88

99
# Divio
1010
.divio
@@ -18,3 +18,5 @@ db.sqlite3
1818
._*
1919
.Spotlight-V100
2020
.Trashes
21+
22+
.idea/

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ WORKDIR /app
33
COPY . /app
44
RUN pip install -r requirements.txt
55
RUN python manage.py collectstatic --noinput
6-
CMD uwsgi --http=0.0.0.0:80 --module=quickstart.wsgi
6+
CMD uwsgi --http=0.0.0.0:80 --module=backend.wsgi

README.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ You need to have docker installed on your system to run this project.
1818
```bash
1919
git clone git@github.com:django-cms/django-cms-quickstart.git
2020
cd django-cms-quickstart
21-
docker-compose build
22-
docker-compose run web python manage.py migrate
23-
docker-compose run web python manage.py createsuperuser
24-
docker-compose up
25-
open http://127.0.0.1:8000
21+
docker compose up --force-recreate --build -d
22+
docker compose run web python manage.py migrate
23+
docker compose run web python manage.py createsuperuser
2624
```
2725

26+
Then open http://django-cms-quickstart.127.0.0.1.nip.io:8000 (or just http://127.0.0.1:8000) in your browser.
2827

2928
## Customising the project
3029

@@ -36,9 +35,35 @@ see sections that can be removed - in each case, the section is noted with a com
3635

3736
Options are also available for using Postgres/MySQL, uWSGI/Gunicorn/Guvicorn, etc.
3837

38+
## Features
39+
40+
### Static Files with Whitenoise
41+
42+
This quickstart demo has a cloud-ready static files setup via django-whitenoise.
43+
44+
In the containerized cloud the application is not served by a web server like nginx but directly through uwsgi. django-whitenoise is the glue that's needed to serve static files in your application directly through uwsgi.
45+
46+
See the django-whitenoise settings in settings.py and the `quickstart/templates/whitenoise-static-files-demo.html` demo page template that serves a static file.
47+
3948
## Contribution
4049

41-
This code for this project has been forked from Divio's quickstart repo. We are grateful for their valueable contribution to the code and documentation of this code.
50+
Here is the official django CMS repository: [https://github.com/django-cms/django-cms-quickstart/](https://github.com/django-cms/django-cms-quickstart/).
51+
52+
53+
## Deployment
54+
55+
Note that this is just a demo project to get you started. If you want a full production ready site with all the bells and whistles we recommend you have a look at https://github.com/django-cms/djangocms-template instead.
56+
57+
#### Env variables
58+
- to deploy this project in testing mode (recommended) set the environment variable `DEBUG` to `True` in your hosting environment.
59+
- For production environment (if `DEBUG` is false) django requires you to whitelist the domain. Set the env var `DOMAIN` to the host, i.e. `www.domain.com` or `*.domain.com`.
60+
- If you want the media hosted on S3 set the `DEFAULT_FILE_STORAGE` variable accordingly.
61+
62+
#### Deployment Commands
63+
Configure your hosting environment to run the following commands on every deployment:
64+
- `./manage.py migrate`
65+
66+
67+
#### Divio Deployment
4268

43-
You can follow the original repo [here](https://github.com/divio/django-cms-divio-quickstart/)
44-
and read their [Divio Developer Handbook](https://docs.divio.com).
69+
divio.com is a cloud hosting platform optimized for django web applications. It's the quickest way to deploy this project. Here is a [video tutorial](https://www.youtube.com/watch?v=O2g5Wfoyp7Q) and a [description of the deployment steps](https://github.com/django-cms/djangocms-template/blob/mco-standalone/docs/deployment-divio.md#divio-project-setup) that are mostly applicable for this quickstart project.
File renamed without changes.

quickstart/asgi.py renamed to backend/asgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
from django.core.asgi import get_asgi_application
1313

14-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'quickstart.settings')
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
1515

1616
application = get_asgi_application()

quickstart/settings.py renamed to backend/settings.py

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@
1111
SECRET_KEY = os.environ.get('SECRET_KEY', '<a string of random characters>')
1212

1313
# SECURITY WARNING: don't run with debug turned on in production!
14-
DEBUG = os.environ.get('DJANGO_DEBUG') == "True"
14+
DEBUG = os.environ.get('DEBUG') == "True"
1515

16-
DIVIO_DOMAIN = os.environ.get('DOMAIN', '')
17-
DIVIO_DOMAIN_ALIASES = [
18-
d.strip()
19-
for d in os.environ.get('DOMAIN_ALIASES', '').split(',')
20-
if d.strip()
21-
]
22-
ALLOWED_HOSTS = [DIVIO_DOMAIN] + DIVIO_DOMAIN_ALIASES
16+
ALLOWED_HOSTS = [os.environ.get('DOMAIN'),]
17+
if DEBUG:
18+
ALLOWED_HOSTS = ["*",]
2319

2420
# Redirect to HTTPS by default, unless explicitly disabled
2521
SECURE_SSL_REDIRECT = os.environ.get('SECURE_SSL_REDIRECT') != "False"
@@ -30,7 +26,7 @@
3026
# Application definition
3127

3228
INSTALLED_APPS = [
33-
'quickstart',
29+
'backend',
3430

3531
# optional, but used in most projects
3632
'djangocms_admin_style',
@@ -40,6 +36,7 @@
4036
'django.contrib.contenttypes',
4137
'django.contrib.sessions',
4238
'django.contrib.messages',
39+
'whitenoise.runserver_nostatic', # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
4340
'django.contrib.staticfiles',
4441
'django.contrib.sites',
4542

@@ -107,7 +104,7 @@
107104
'cms.middleware.language.LanguageCookieMiddleware',
108105
]
109106

110-
ROOT_URLCONF = 'quickstart.urls'
107+
ROOT_URLCONF = 'backend.urls'
111108

112109
TEMPLATES = [
113110
{
@@ -136,13 +133,14 @@
136133
CMS_TEMPLATES = [
137134
# a minimal template to get started with
138135
('minimal.html', 'Minimal template'),
136+
('whitenoise-static-files-demo.html', 'Static File Demo'),
139137

140138
# optional templates that extend base.html, to be used with Bootstrap 4
141139
('page.html', 'Page'),
142140
('feature.html', 'Page with Feature')
143141
]
144142

145-
WSGI_APPLICATION = 'quickstart.wsgi.application'
143+
WSGI_APPLICATION = 'backend.wsgi.application'
146144

147145

148146
# Database
@@ -151,39 +149,27 @@
151149
# Configure database using DATABASE_URL; fall back to sqlite in memory when no
152150
# environment variable is available, e.g. during Docker build
153151
DATABASE_URL = os.environ.get('DATABASE_URL', 'sqlite://:memory:')
154-
155-
if not os.environ.get('CI', False):
156-
DATABASES = {'default': dj_database_url.parse(DATABASE_URL)}
157-
else:
158-
DATABASES = {
159-
'default': {
160-
'ENGINE': 'django.db.backends.postgresql',
161-
'NAME': 'postgres',
162-
'USER': 'postgres',
163-
'PASSWORD': 'postgres',
164-
'HOST': '127.0.0.1',
165-
'PORT': '5432',
166-
}
167-
}
152+
DATABASES = {'default': dj_database_url.parse(DATABASE_URL)}
168153

169154

170155
# Password validation
171156
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
172157

173-
AUTH_PASSWORD_VALIDATORS = [
174-
{
175-
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
176-
},
177-
{
178-
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
179-
},
180-
{
181-
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
182-
},
183-
{
184-
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
185-
},
186-
]
158+
if not DEBUG:
159+
AUTH_PASSWORD_VALIDATORS = [
160+
{
161+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
162+
},
163+
{
164+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
165+
},
166+
{
167+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
168+
},
169+
{
170+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
171+
},
172+
]
187173

188174

189175
# Internationalization
@@ -208,7 +194,7 @@
208194
# https://docs.djangoproject.com/en/3.1/howto/static-files/
209195

210196
STATIC_URL = '/static/'
211-
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
197+
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles_collected')
212198
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
213199

214200
# Media files
@@ -221,7 +207,7 @@
221207
DefaultStorageClass = dsn_configured_storage_class('DEFAULT_STORAGE_DSN')
222208

223209
# Django's DEFAULT_FILE_STORAGE requires the class name
224-
DEFAULT_FILE_STORAGE = 'quickstart.settings.DefaultStorageClass'
210+
DEFAULT_FILE_STORAGE = 'backend.settings.DefaultStorageClass'
225211

226212
# only required for local file storage and serving, in development
227213
MEDIA_URL = 'media/'

backend/static/django-cms-logo.png

12.6 KB
Loading
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)