All Projects → fiee → Generic_django_project

fiee / Generic_django_project

starting point for a new Django site (with FeinCMS, deployable on Nginx using Fabric)

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Generic django project

Dailyfresh
Django-天天生鲜电商学习项目
Stars: ✭ 127 (+67.11%)
Mutual labels:  django, nginx
Docker Django Nginx Uwsgi Postgres Tutorial
Docker + Django + Nginx + uWSGI + Postgres 基本教學 - 從無到有 ( Docker + Django + Nginx + uWSGI + Postgres Tutorial )
Stars: ✭ 334 (+339.47%)
Mutual labels:  django, nginx
Django Celery Docker Example
Example Docker setup for a Django app behind an Nginx proxy with Celery workers
Stars: ✭ 149 (+96.05%)
Mutual labels:  django, nginx
Docker Nginx Postgres Django Example
Example using Docker, Django, multiple Postgres databases, NginX, Gunicorn, pipenv, GitLab CI and tox.
Stars: ✭ 110 (+44.74%)
Mutual labels:  django, nginx
Lazy Balancer
nginx for balancer web ui
Stars: ✭ 499 (+556.58%)
Mutual labels:  django, nginx
Hydroshare
HydroShare is a collaborative website for better access to data and models in the hydrologic sciences.
Stars: ✭ 117 (+53.95%)
Mutual labels:  django, nginx
Opensa
资产管理、资产采集、灰度发布、反向代理、批量任务、任务编排、计划任务、日志审计、权限管理、角色管理、部门管理、运维自动化
Stars: ✭ 220 (+189.47%)
Mutual labels:  django, nginx
Docker Django
A project to get you started with Docker and Django.
Stars: ✭ 170 (+123.68%)
Mutual labels:  django, nginx
Django React Boilerplate
DIY Django + React Boilerplate for starting your SaaS
Stars: ✭ 385 (+406.58%)
Mutual labels:  django, nginx
Docker Django
A complete docker package for deploying django which is easy to understand and deploy anywhere.
Stars: ✭ 378 (+397.37%)
Mutual labels:  django, nginx
Bubbly
Better SSL in Nginx in 10 minutes. Configuration files and setup scripts for Certbot.
Stars: ✭ 213 (+180.26%)
Mutual labels:  certbot, nginx
Opman Django
💯✅自动化运维平台:CMDB、CI/CD、DevOps、资产管理、任务编排、持续交付、系统监控、运维管理、配置管理
Stars: ✭ 539 (+609.21%)
Mutual labels:  django, nginx
Serverpilot Letsencrypt
Automate the installation of Let's Encrypt SSL on the free plan of ServerPilot
Stars: ✭ 129 (+69.74%)
Mutual labels:  certbot, nginx
Django Microservices
UNMAINTAINED
Stars: ✭ 124 (+63.16%)
Mutual labels:  django, nginx
Dockerweb
A docker-powered bash script for shared web hosting management. The ultimate Docker LAMP/LEMP Stack.
Stars: ✭ 89 (+17.11%)
Mutual labels:  certbot, nginx
Autoops
linux资产管理,cmdb,django, webssh,运维管理平台,数据库操作平台 本项目已停止开发!因长时间未对代码进行维护,可能会造成项目在不同环境上无法部署、运行BUG等问题,请知晓!项目仅供参考!
Stars: ✭ 340 (+347.37%)
Mutual labels:  django, nginx
Wordpress Nginx Docker
Wordpress (php7.3-fpm) using Nginx and MariaDB - deployed with docker-compose - Let's Encrypt enabled
Stars: ✭ 498 (+555.26%)
Mutual labels:  certbot, nginx
Docker Nginx Letsencrypt Upstream
infrastructure: docker-compose config for node and redis behind upstream nginx ( SSL/HTTPS ) on debian jessie
Stars: ✭ 47 (-38.16%)
Mutual labels:  certbot, nginx
Django Likes
Django app providing view interface to django-secretballot.
Stars: ✭ 72 (-5.26%)
Mutual labels:  django
Openstax Cms
The OpenStax CMS, built using Wagtail on top of Django.
Stars: ✭ 74 (-2.63%)
Mutual labels:  django

====================== generic django project

This is my starting point for a new Django_ site, mixed and stirred from several public sources and spiced with my own enhancements.

I usually work with FeinCMS_ and its medialibrary_, this is reflected in my setups.

My webserver of choice is Nginx_ with gunicorn_.


Requirements

  • server OS: Debian/Ubuntu based Linux
  • local OS: macOS (only some local settings are OSX specific)
  • web server: Nginx/gunicorn
  • Python_ version: 3.6+
  • Django_ version: 2.2
  • FeinCMS_ version: 1.17+
  • version control: Git_ (with a remote git host)
  • deployment tool: Fabric_
  • local development database: SQLite3_ or MariaDb/MySQL_
  • server database: MariaDb/MySQL_
  • process control (optional): supervisord_

Rationale

I don’t know if this still makes sense, but while I update some sites from Django 1.9 to 3.0 I also update this.

Django’s startproject doesn’t do enough. I’m a programmer, thus lazy, and try to reduce redundant work like repeating the same setup steps over and over. (DRY)

Just copying/cloning this generic project to a new site isn’t ideal either, since general changes don’t affect all dependent sites, but I got no idea how to do that.


Issues

I’m trying to keep this current and to implement what I learn from my actual projects and best practice advise. But since I mostly do other things than starting new django projects, I’m always far behind.

  • While I try to adhere to best practices, there are probably security holes - use at your own risk.
  • Since I update this template after experiences with my actual sites, the commits are often not atomic.
  • I handle migrations wrongly, will try to fix soon.
  • pip-installed requirements are not fixed on a version.
  • I could also support runit_, but I didn't want to replace init.
  • PostgreSQL would make sense, but I don’t need it.

Details

  • gunicorn runs internally on an unix socket, because I find file locations easier to control than server ports.
  • My earlier Fabric workflow used only local git and pushed a package to the web server. Now I’m relying on my private git server (gitolite) and doing away with different releases on the web server. This might also fit some shared hosting providers with git-enabled Plesk.
  • I’m using Let’s Encrypt certificates with certbot.
  • My nginx settings get an A+ rating at SSLLabs_ (still?)

Ideas


License

This project template itself has no special license. Do with it what you want. Attribution is appreciated. Corrections are welcome. I’m not responsible for your failure, damage or loss.

Since it’s a collection of (modified) snippets from different sources that may have different licenses, it would be impossible to untangle.

Following Django’s documentation I suggest to use a 2-clause BSD license for your own reusable projects.


How To

local:

  • Copy generic_django_project
  • Rename "django_project" (this would be the project root as created by django-admin.py startproject)
  • Replace all occurrences of lowercase "project_name" with your project name. This is also the webserver and database server username! The "project_name" directory is the one that would be created by manage.py startapp.
  • Check the settings in server-setup and django_project/settings: fabfile.py_, gunicorn-settings.py_, supervisor.conf_, settings/base.py_, settings/local.py_ etc.
  • Adapt LICENSE_ to your needs if you might publish your project. The 2-clause BSD license is just a suggestion.
  • Set up an email account for your project’s error messages and configure it in settings/base.py_ and .env
  • cd into your project directory, virtualenv . (create virtual environment; make sure you use the right version)
  • . bin/activate (activate virtual environment)
  • bin/pip install -r requirements/local.txt (install requirements)
  • cd <project_name>
  • vi .env (create .env file, see below)
  • ./manage.py migrate (initialize migrations)
  • git init, always commit all changes
  • fab webserver setup (once)
  • fab webserver deploy (publish new release - always last committed version!)

Following 12-factor_ design, we now set our passwords and other secret settings as environment variables to avoid to have them in version control. I suggest to go the dotenv route:

Put your settings into a .env file in the django_project directory, to use with django-dotenv_. Don’t forget to tell git to ignore .env files! ::

  DJANGO_SETTINGS_MODULE=settings
  SECRET_KEY=secret123
  DATABASE_PASSWORD=secret123
  EMAIL_PASSWORD=secret123

Alternatively add the settings to the end of your virtualenvs_ activate script: ::

  export DJANGO_SETTINGS_MODULE=settings
  export SECRET_KEY=secret123
  export DATABASE_PASSWORD=secret123
  export EMAIL_PASSWORD=secret123

server:

  • Create the user

    I suggest to copy makeuser.sh_ to your webserver’s root/admin account and use it to create system and database accounts.

    scp makeuser.sh [email protected]:/root/bin/
    

    Otherwise look into that script. This is just a part of the necessary setup:

    • create user and sudo-enable it (I suggest via a admin group, but you can also add the user to sudoers): ::

      adduser project_name --disabled-password --gecos "" adduser project_name admin

      REM: It’s possible to avoid sudo rights for each website user, but then you need to run some commands as root or as an other sudo-enabled user.

    • create database user and database (schema): ::

      mysql -u root -p

      at first setup only: we installed MySQL without user interaction,

      so there’s no root password. Set it!

      use mysql; update user set password=password('...') where user='root';

      create user and database for our project:

      create user 'project_name'@'localhost' identified by '...'; create database project_name character set 'utf8'; grant all privileges on project_name.* to 'project_name'@'localhost';

      flush privileges; quit;

  • Create your .env file at /var/www/project_name (or use virtualenvs_’ activate script), see above.

  • publish your project (fab webserver setup)

  • Open your firewall for tcp 433 (not default on some systems).

  • Create a ssh key for the new user: ::

    ssh-keygen -b 4096

  • Add this key to your git server’s access configuration, e.g. like ::

    scp [email protected]:/home/project_name/.ssh/id_rsa.pub gitolite-admin/keydir/[email protected]

    You need read access for project_name on the web server and write access for your development user.

  • Publish your project to your git server and clone the project on your web server, e.g. as /var/www/project_name/project_name.

  • Activate the project in supervisor.

  • Run certbot to acquire a SSL certificate for your project.

  • (This is WIP)

FeinCMS

If you use FeinCMS’ Page, consider first, which extensions you’ll need – see the docs <http://feincms-django-cms.readthedocs.io/en/latest/page.html#module-feincms.module.page.extension>_ – the migration is somewhat tricky.

Since the setup requires monkey patching FeinCMS’s models, you must pull their migrations into your app, as outlined in the docs <http://feincms-django-cms.readthedocs.io/en/latest/migrations.html>. The same is true for Plata.

Have a look at Feinheit’s FeinCMS compatible apps, content types and plugins: ElephantBlog_, Plata_, form_designer_ etc. (REM: They’re mostly outdated.)

Instead of FeinCMS’s medialibrary, consider to use django-filer_ instead, there’s some support for it in FeinCMS, but not yet here.


Links / Sources

Everything:

  • Two Scoops of Django_

Setup:

Modules:

.. _Python: http://www.python.org .. _Git: http://git-scm.com/ .. _Nginx: http://wiki.nginx.org .. _Django: http://www.djangoproject.com/ .. _Fabric: http://docs.fabfile.org .. _fabfile: http://docs.fabfile.org .. _django-filer: https://django-filer.readthedocs.io .. _MPTT: http://github.com/django-mptt/django-mptt .. _FeinCMS: http://github.com/feincms/feincms .. _medialibrary: http://feincms-django-cms.readthedocs.io/en/latest/medialibrary.html .. _Plata: https://github.com/fiee/plata .. _ElephantBlog: https://github.com/feincms/feincms-elephantblog .. _form_designer: https://github.com/feincms/form_designer .. _feincms_gallery: https://github.com/feinheit/feincms_gallery .. _Schedule: http://github.com/fiee/django-schedule .. _gunicorn: http://gunicorn.org/ .. _mod_wsgi: http://modwsgi.readthedocs.org .. _fcgi: http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/ .. _MySQL: http://mysql.com/products/community/ .. _PostgreSQL: http://www.postgresql.org/ .. _SQLite3: http://www.sqlite.org/ .. _daemontools: http://cr.yp.to/daemontools.html .. _supervisord: http://supervisord.org .. _runit: http://smarden.org/runit/ .. _logrotate: http://www.linux-praxis.de/lpic1/manpages/logrotate.html .. _virtualenvs: http://virtualenv.readthedocs.org/ .. _Redis: http://redis.io .. _Two Scoops of Django: http://twoscoopspress.org/products/two-scoops-of-django-1-6 .. _django-dotenv: https://pypi.python.org/pypi/django-dotenv/ .. _12-factor: http://12factor.net .. _maintenance page: http://www.djangocurrent.com/2015/12/automatic-maintenance-page-for.html

.. _LICENSE: blob/master/reusable_app_project/LICENSE .. _makeuser.sh: blob/master/tools/makeuser.sh .. _manage.py: blob/master/django_project/manage.py .. _base.py: blob/master/django_project/project_name/settings/base.py .. _local.py: blob/master/django_project/project_name/settings/local.py .. _gunicorn-settings.py: blob/master/server-setup/gunicorn-settings.py .. _fabfile.py: blob/master/fabfile.py .. _supervisor.conf: blob/master/server-setup/supervisor.ini .. _service-run.sh: blob/master/server-setup/service-run.sh .. _nginx.conf: blob/master/server-setup/nginx.conf

.. _SSLLabs: https://www.ssllabs.com/ssltest/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].