diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 3a068e318..de52d435f 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -89,6 +89,7 @@ Listed in alphabetical order. Ian Lee `@IanLee1521`_ Jan Van Bruggen `@jvanbrug`_ Jens Nilsson `@phiberjenz`_ + Jimmy Gitonga `@afrowave`_ @afrowave Julien Almarcha `@sladinji`_ Julio Castillo `@juliocc`_ Kaido Kert `@kaidokert`_ @@ -106,11 +107,14 @@ Listed in alphabetical order. Lyla Fischer Martin Blech Mathijs Hoogland `@MathijsHoogland`_ + Matt Braymer-Hayes `@mattayes`_ @mattayes Matt Linares Matt Menzenski `@menzenski`_ Matt Warren `@mfwarren`_ Matthew Sisley `@mjsisley`_ Meghan Heintz `@dot2dotseurat`_ + Mesut Yılmaz `@myilmaz`_ + Michael Gecht `@mimischi`_ @_mischi mozillazg `@mozillazg`_ Pablo `@oubiga`_ Parbhat Puri `@parbhat`_ @@ -122,13 +126,15 @@ Listed in alphabetical order. Roman Osipenko `@romanosipenko`_ Russell Davies Sam Collins `@MightySCollins`_ - stepmr `@stepmr`_ + Shupeyko Nikita `@webyneter`_ Sławek Ehlert `@slafs`_ Srinivas Nyayapati `@shireenrao`_ + stepmr `@stepmr`_ Steve Steiner `@ssteinerX`_ Sule Marshall `@suledev`_ Taylor Baldwin Théo Segonds `@show0k`_ + Tim Freund `@timfreund`_ Tom Atkins `@knitatoms`_ Tom Offermann Travis McNeill `@Travistock`_ @tavistock_esq @@ -190,9 +196,12 @@ Listed in alphabetical order. .. _@knitatoms: https://github.com/knitatoms .. _@krzysztofzuraw: https://github.com/krzysztofzuraw .. _@MathijsHoogland: https://github.com/MathijsHoogland +.. _@mattayes: https://github.com/mattayes .. _@menzenski: https://github.com/menzenski .. _@mfwarren: https://github.com/mfwarren +.. _@mimischi: https://github.com/mimischi .. _@mjsisley: https://github.com/mjsisley +.. _@myilmaz: https://github.com/myilmaz .. _@mozillazg: https://github.com/mozillazg .. _@noisy: https://github.com/noisy .. _@originell: https://github.com/originell @@ -202,6 +211,7 @@ Listed in alphabetical order. .. _@rm--: https://github.com/rm-- .. _@romanosipenko: https://github.com/romanosipenko .. _@shireenrao: https://github.com/shireenrao +.. _@webyneter: https://github.com/webyneter .. _@show0k: https://github.com/show0k .. _@shultz: https://github.com/shultz .. _@siauPatrick: https://github.com/siauPatrick @@ -209,6 +219,7 @@ Listed in alphabetical order. .. _@ssteinerX: https://github.com/ssteinerx .. _@stepmr: https://github.com/stepmr .. _@suledev: https://github.com/suledev +.. _@timfreund: https://github.com/timfreund .. _@Travistock: https://github.com/Tavistock .. _@trungdong: https://github.com/trungdong .. _@viviangb: httpsL//github.com/viviangb diff --git a/README.rst b/README.rst index 95e90afb2..3660b4d32 100644 --- a/README.rst +++ b/README.rst @@ -16,12 +16,14 @@ Powered by Cookiecutter_, Cookiecutter Django is a framework for jumpstarting pr * Documentation: https://cookiecutter-django.readthedocs.io/en/latest/ * See Troubleshooting_ for common errors and obstacles +* If you have problems with Cookiecutter Django, please open issues_ before sending emails to the maintainers. You will get a much, MUCH faster response. .. _cookiecutter: https://github.com/audreyr/cookiecutter .. _Troubleshooting: https://cookiecutter-django.readthedocs.io/en/latest/troubleshooting.html .. _528: https://github.com/pydanny/cookiecutter-django/issues/528#issuecomment-212650373 +.. _issues: https://github.com/pydanny/cookiecutter-django/issues/new Features --------- @@ -30,6 +32,7 @@ Features * Renders Django projects with 100% starting test coverage * Twitter Bootstrap_ v4.0.0 - `alpha 4`_ (`maintained Foundation fork`_ also available) * 12-Factor_ based settings via django-environ_ +* Secure by default. We believe in SSL. * Optimized development and production settings * Registration via django-allauth_ * Comes with custom user model ready to go @@ -70,7 +73,7 @@ Optional Integrations .. _Celery: http://www.celeryproject.org/ .. _Anymail: https://github.com/anymail/django-anymail .. _MailHog: https://github.com/mailhog/MailHog -.. _Sentry: https://getsentry.com/welcome/ +.. _Sentry: https://sentry.io/welcome/ .. _docker-compose: https://github.com/docker/compose .. _Opbeat: https://opbeat.com/ .. _PythonAnywhere: https://www.pythonanywhere.com/ @@ -191,6 +194,13 @@ For Readers of Two Scoops of Django 1.8 You may notice that some elements of this project do not exactly match what we describe in chapter 3. The reason for that is this project, amongst other things, serves as a test bed for trying out new ideas and concepts. Sometimes they work, sometimes they don't, but the end result is that it won't necessarily match precisely what is described in the book I co-authored. +For pyup.io Users +----------------- + +If you are using `pyup.io`_ to keep your dependencies updated and secure, use the code *cookiecutter* during checkout to get 15% off every month. + +.. _`pyup.io`: https://pyup.io + "Your Stuff" ------------- diff --git a/cookiecutter.json b/cookiecutter.json index bf729b678..0bc2b90e2 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -15,11 +15,11 @@ "use_pycharm": "n", "windows": "n", "use_python3": "y", - "use_docker": "y", + "use_docker": "n", "use_heroku": "n", "use_elasticbeanstalk_experimental": "n", "use_compressor": "n", - "postgresql_version": ["9.5", "9.4", "9.3", "9.2"], + "postgresql_version": ["9.6", "9.5", "9.4", "9.3", "9.2"], "js_task_runner": ["Gulp", "Grunt", "None"], "use_lets_encrypt": "n", "open_source_license": ["MIT", "BSD", "GPLv3", "Apache Software License 2.0", "Not open source"] diff --git a/docs/deployment-on-heroku.rst b/docs/deployment-on-heroku.rst index 843e230fb..b84edfa46 100644 --- a/docs/deployment-on-heroku.rst +++ b/docs/deployment-on-heroku.rst @@ -3,7 +3,7 @@ Deployment on Heroku .. index:: Heroku -You can either push the 'deploy' button in your generated README.rst or run these commands to deploy the project to Heroku: +Run these commands to deploy the project to Heroku: .. code-block:: bash diff --git a/docs/deployment-on-pythonanywhere.rst b/docs/deployment-on-pythonanywhere.rst index 82399eb15..93f189601 100644 --- a/docs/deployment-on-pythonanywhere.rst +++ b/docs/deployment-on-pythonanywhere.rst @@ -47,7 +47,7 @@ Generate a secret key for yourself, eg like this: .. code-block:: bash - python -c 'import random; print("".join(random.SystemRandom().choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)") for _ in range(50)))' + python -c 'import random;import string; print("".join(random.SystemRandom().choice(string.digits + string.ascii_letters + string.punctuation) for _ in range(50)))' Make a note of it, since we'll need it here in the console and later on in the web app config tab. @@ -179,5 +179,3 @@ For subsequent deployments, the procedure is much simpler. In a Bash console: And then go to the Web tab and hit **Reload** **TIP:** *if you're really keen, you can set up git-push based deployments: https://blog.pythonanywhere.com/87/* - - diff --git a/docs/deployment-with-docker.rst b/docs/deployment-with-docker.rst index 03aefd486..5025cdd37 100644 --- a/docs/deployment-with-docker.rst +++ b/docs/deployment-with-docker.rst @@ -37,6 +37,19 @@ root directory of this project as a starting point. Add your own variables to th file won't be tracked by git by default so you'll have to make sure to use some other mechanism to copy your secret if you are relying solely on git. +HTTPS is on by default +---------------------- + +SSL (Secure Sockets Layer) is a standard security technology for establishing an encrypted link between a server and a client, typically in this case, a web server (website) and a browser. Not having HTTPS means that malicious network users can sniff authentication credentials between your website and end users' browser. + +It is always better to deploy a site behind HTTPS and will become crucial as the web services extend to the IoT (Internet of Things). For this reason, we have set up a number of security defaults to help make your website secure: + +* In the `.env.example`, we have made it simpler for you to change the default `Django Admin` into a custom name through an environmental variable. This should make it harder to guess the access to the admin panel. + +* If you are not using a subdomain of the domain name set in the project, then remember to put the your staging/production IP address in the ``ALLOWED_HOSTS``_ environment variable before you deploy your website. Failure to do this will mean you will not have access to your website through the HTTP protocol. + +* Access to the Django admin is set up by default to require HTTPS in production or once *live*. We recommend that you look into setting up the *Certbot and Let's Encrypt Setup* mentioned below or another HTTPS certification service. + Optional: nginx-proxy Setup --------------------------- @@ -52,8 +65,7 @@ This pass all incoming requests on `nginx-proxy`_ to the nginx service your appl Optional: Postgres Data Volume Modifications --------------------------------------------- -Postgres is saving its database files to the `postgres_data` volume by default. Change that if you wan't -something else and make sure to make backups since this is not done automatically. +Postgres is saving its database files to the `postgres_data` volume by default. Change that if you want something else and make sure to make backups since this is not done automatically. Optional: Certbot and Let's Encrypt Setup ------------------------------------------ @@ -143,7 +155,7 @@ If you have errors, you can always check your stack with `docker-compose`. Switc Supervisor Example ------------------- -Once you are ready with your initial setup, you wan't to make sure that your application is run by a process manager to +Once you are ready with your initial setup, you want to make sure that your application is run by a process manager to survive reboots and auto restarts in case of an error. You can use the process manager you are most familiar with. All it needs to do is to run `docker-compose up` in your projects root directory. diff --git a/docs/developing-locally-docker.rst b/docs/developing-locally-docker.rst index 65312e8d7..19c24f8e5 100644 --- a/docs/developing-locally-docker.rst +++ b/docs/developing-locally-docker.rst @@ -20,6 +20,16 @@ If you don't already have it installed, follow the instructions for your OS: .. _`Docker for Windows`: https://docs.docker.com/engine/installation/windows/ .. _`docker-engine`: https://docs.docker.com/engine/installation/ +Attention Windows users +------------- + +Currently PostgreSQL (``psycopg2`` python package) is not installed inside Docker containers for Windows users, while it is required by the generated Django project. To fix this, add ``psycopg2`` to the list of requirements inside ``requirements/base.txt``:: + + # Python-PostgreSQL Database Adapter + psycopg2==2.6.2 + +Doing this will prevent the project from being installed in an Windows-only environment (thus without usage of Docker). If you want to use this project without Docker, make sure to remove ``psycopg2`` from the requirements again. + Build the Stack --------------- @@ -63,6 +73,11 @@ To migrate your app and to create a superuser, run:: Here we specify the ``django`` container as the location to run our management commands. +Add your Docker development server IP +------------------------------------ + +When ``DEBUG`` is set to `True`, the host is validated against ``['localhost', '127.0.0.1', '[::1]']``. This is adequate when running a ``virtualenv``. For Docker, in the ``config.settings.local``, add your host development server IP to ``INTERNAL_IPS`` or ``ALLOWED_HOSTS`` if the variable exists. + Production Mode ~~~~~~~~~~~~~~~ diff --git a/docs/developing-locally.rst b/docs/developing-locally.rst index 6c84ca3c2..8aae8f0bd 100644 --- a/docs/developing-locally.rst +++ b/docs/developing-locally.rst @@ -50,7 +50,7 @@ Setup your email backend django-allauth sends an email to verify users (and superusers) after signup and login (if they are still not verified). To send email you need to `configure your email backend`_ -.. _configure your email backend: http://docs.djangoproject.com/en/1.9/topics/email/#smtp-backend +.. _configure your email backend: https://docs.djangoproject.com/en/dev/topics/email/#smtp-backend In development you can (optionally) use MailHog_ for email testing. MailHog is built with Go so there are no dependencies. To use MailHog: diff --git a/docs/project-generation-options.rst b/docs/project-generation-options.rst index c2b14e874..abedb4aa5 100644 --- a/docs/project-generation-options.rst +++ b/docs/project-generation-options.rst @@ -25,7 +25,7 @@ version [0.1.0] The starting version number for your project. timezone [UTC] - Used in the common settings file for the `TIME_ZONE` value. + Used in the base settings file for the `TIME_ZONE` value. use_whitenoise [y] Whether to use WhiteNoise_ for static file serving. diff --git a/docs/settings.rst b/docs/settings.rst index eb6e92a45..893a47e90 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -3,7 +3,14 @@ Settings This project relies extensively on environment settings which **will not work with Apache/mod_wsgi setups**. It has been deployed successfully with both Gunicorn/Nginx and even uWSGI/Nginx. -For configuration purposes, the following table maps environment variables to their Django setting: +For configuration purposes, the following table maps environment variables to their Django setting and project settings: + + +======================================= =========================== ============================================== ====================================================================== +Environment Variable Django Setting Development Default Production Default +======================================= =========================== ============================================== ====================================================================== +DJANGO_READ_DOT_ENV_FILE READ_DOT_ENV_FILE False False +======================================= =========================== ============================================== ====================================================================== ======================================= =========================== ============================================== ====================================================================== diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 068d74831..4a9d14e2f 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -16,6 +16,7 @@ from __future__ import print_function import os import random import shutil +import string # Get the root project directory PROJECT_DIRECTORY = os.path.realpath(os.path.curdir) @@ -28,16 +29,19 @@ except NotImplementedError: using_sysrandom = False -def get_random_string( - length=50, - allowed_chars='abcdefghijklmnopqrstuvwxyz0123456789!@#%^&*(-_=+)'): +def get_random_string(length=50): """ Returns a securely generated random string. The default length of 12 with the a-z, A-Z, 0-9 character set returns a 71-bit value. log_2((26+26+10)^12) =~ 71 bits """ + punctuation = string.punctuation.replace('"', '').replace("'", '') + punctuation = punctuation.replace('\\', '') if using_sysrandom: - return ''.join(random.choice(allowed_chars) for i in range(length)) + return ''.join(random.choice( + string.digits + string.ascii_letters + punctuation + ) for i in range(length)) + print( "Cookiecutter Django couldn't find a secure pseudo-random number generator on your system." " Please change change your SECRET_KEY variables in conf/settings/local.py and env.example" diff --git a/requirements.txt b/requirements.txt index 73e90f9a6..0e5486874 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,11 @@ -cookiecutter==1.4.0 -flake8==3.0.4 # pyup: != 2.6.0 -sh==1.11 +cookiecutter==1.5.1 +flake8==3.2.1 # pyup: != 2.6.0 +sh==1.12.9 binaryornot==0.4.0 # Testing -pytest==3.0.3 +pytest==3.0.6 pep8==1.7.0 -pyflakes==1.3.0 -tox==2.4.1 +pyflakes==1.5.0 +tox==2.6.0 pytest-cookies==0.2.0 diff --git a/requirements_to_watch.txt b/requirements_to_watch.txt index 34f0fe621..4440448d4 100644 --- a/requirements_to_watch.txt +++ b/requirements_to_watch.txt @@ -1,4 +1,4 @@ # These requirements prevented an upgrade to Django 1.10. -django-coverage-plugin==1.3.1 +django-coverage-plugin==1.5.0 django-autoslug==1.9.3 diff --git a/tests/test_docker.sh b/tests/test_docker.sh index ced9b1829..3c047f0a3 100755 --- a/tests/test_docker.sh +++ b/tests/test_docker.sh @@ -11,7 +11,7 @@ mkdir -p .cache/docker cd .cache/docker # create the project using the default settings in cookiecutter.json -cookiecutter ../../ --no-input --overwrite-if-exists +cookiecutter ../../ --no-input --overwrite-if-exists use_docker=y js_task_runner=None cd project_name # run the project's tests diff --git a/{{cookiecutter.project_slug}}/.ebextensions/50_apache.config b/{{cookiecutter.project_slug}}/.ebextensions/50_apache.config new file mode 100644 index 000000000..672cb625b --- /dev/null +++ b/{{cookiecutter.project_slug}}/.ebextensions/50_apache.config @@ -0,0 +1,3 @@ +container_commands: + 01_setup_apache: + command: "cp .ebextensions/enable_mod_deflate.conf /etc/httpd/conf.d/enable_mod_deflate.conf" diff --git a/{{cookiecutter.project_slug}}/.ebextensions/enable_mod_deflate.conf b/{{cookiecutter.project_slug}}/.ebextensions/enable_mod_deflate.conf new file mode 100644 index 000000000..7a77cc234 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.ebextensions/enable_mod_deflate.conf @@ -0,0 +1,25 @@ +# mod_deflate configuration + + # Restrict compression to these MIME types + AddOutputFilterByType DEFLATE text/plain + AddOutputFilterByType DEFLATE text/html + AddOutputFilterByType DEFLATE application/xhtml+xml + AddOutputFilterByType DEFLATE text/xml + AddOutputFilterByType DEFLATE application/xml + AddOutputFilterByType DEFLATE application/xml+rss + AddOutputFilterByType DEFLATE application/x-javascript + AddOutputFilterByType DEFLATE text/javascript + AddOutputFilterByType DEFLATE text/css + # Level of compression (Highest 9 - Lowest 1) + DeflateCompressionLevel 9 + # Netscape 4.x has some problems. + BrowserMatch ^Mozilla/4 gzip-only-text/html + # Netscape 4.06-4.08 have some more problems + BrowserMatch ^Mozilla/4\.0[678] no-gzip + # MSIE masquerades as Netscape, but it is fine + BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html + + # Make sure proxies don't deliver the wrong content + Header append Vary User-Agent env=!dont-vary + + diff --git a/{{cookiecutter.project_slug}}/.idea/runConfigurations/Docker__tests___all.xml b/{{cookiecutter.project_slug}}/.idea/runConfigurations/Docker__tests___all.xml index 7ede8bfb5..02fba0797 100644 --- a/{{cookiecutter.project_slug}}/.idea/runConfigurations/Docker__tests___all.xml +++ b/{{cookiecutter.project_slug}}/.idea/runConfigurations/Docker__tests___all.xml @@ -4,7 +4,7 @@