Welcome to Django Base’s documentation!

Django Base

https://travis-ci.org/tyagow/django-base.svg?branch=master

Documentation

The full documentation is at http://django-base.readthedocs.io.

Live demo @ http://django-base.104.236.104.21.xip.io

Quickstart

  1. Clone o repositório.
  2. Crie um virutalenv com o Python 3.5
  3. Ative o Virtualenv.
  4. Instale as dependencias.

5. Configure as variaveis sensiveis do projeto com o .env 5. Configure as variaveis referentes ao dokku no arquivo deploy_utlis/.env 6. Migre seus modelos para o Banco de Dados 7. Roda o collectstatic para configurar arquivos staticos 8. Execute os testes.

Digite no terminal:

git clone https://github.com/tyagow/django-base.git Nome-Do-Projeto
cd Nome-Do-Projeto
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp contrib/env-sample .env
cp contrib/env-d0kku-sample deploy_utlis/.env
python manage.py collectstatic
python manage.py migrate
python manage.py test
python manage.py runserver

Como fazer o Deploy?

Como fazer o Deploy?

Features

  • Django 1.10.5
  • Bootstrap 4 alpha 6
  • JQuery 3.1.1
  • Python Decouple
  • DJ Static (serving static files locally)
  • Dj Database URL
  • Django test without migrations
  • Django Crispy Forms
  • Django bootstrap3
  • Social User Login App* (facebook e twitter)
  • Django Extensions
  • Dokku pre configured
  • Multi languange i18n
  • Coverage

Need additional configuration

Social Auth

  • Adicionar ao INSTALLED_APPS
'social_django',
  • Adicionar ao settings.py
AUTHENTICATION_BACKENDS = (
  'social_core.backends.twitter.TwitterOAuth',
  'social_core.backends.facebook.FacebookOAuth2',
  'django.contrib.auth.backends.ModelBackend',
)
  • Adicionar ao requirements.txt
social-auth-app-django
  • Adicionar ao urls.py
url('', include('social_django.urls', namespace='social'))
  • Adicionar ao MIDDLEWARE_CLASSES
'social_django.middleware.SocialAuthExceptionMiddleware',
  • Adicionar ao TEMPLATES
'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
  • Configurar variaveis no .env e no servidor
SOCIAL_AUTH_TWITTER_KEY=
SOCIAL_AUTH_TWITTER_SECRET=
SOCIAL_AUTH_FACEBOOK_KEY=
SOCIAL_AUTH_FACEBOOK_SECRET=

Running Tests

Does the code actually work?

source .venv/bin/activate
(myenv) $ python manage.py test

Installation

  1. Clone o repositório.
  2. Crie um virutalenv com o Python 3.5
  3. Ative o Virtualenv.
  4. Instale as dependencias.
  5. Configure a instancia com o .env
  6. Migre seus modelos para o Banco de Dados
  7. Roda o collectstatic para configurar arquivos staticos
  8. Execute os testes.

Digite no terminal:

git clone https://github.com/tyagow/django-base.git Nome-Do-Projeto
cd Nome-Do-Projeto
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp contrib/env-sample .env
python manage.py collectstatic
python manage.py migrate
python manage.py test
python manage.py runserver

Usage

Translation

Complilar textos a serem traduzidos

  • Criar uma pasta locale dentro de cada App que será traduzido.

  • Criar arquivo para as mensagens a serem traduzidas:

    django-admin makemessages -l en
    

*O ultimo parametro é referente a linguagem que o arquivo será traduzida

  • Traduzir o arquivo django.po

  • Compliar arquivo traduzido:

    django-admin compilemessages
    

NOTES

  • Não traduzir palavras dentro de {} pois são variáveis usadas pelo django e não texto a ser traduzido.

Como fazer o Deploy?

  1. Install Digital Ocean Dokku image
  2. Send your ssh-key to dokku
  3. Connect via ssh to your server
  4. Create app in dokku
  5. Install postgres plugin in dokku
  6. Create database for your app in dokku
  7. Link database and app in dokku
  8. Set DEBUG in dokku
  9. Generate new SECRET_KEY
  10. Set SECRET_KEY in dokku
  11. Set ALLOWED_HOSTS in dokku
  12. Set Global Domain dor dokku
  13. Push your code to dokku
  14. Run the migrations
  15. Collect static data with DEBUG=False

Digite no terminal

(local) cat ~/.ssh/id_rsa.pub | ssh root@<your.ip.address> "sudo sshcommand acl-add dokku [description]"
(local) ssh root@<your.ip.address>
(server) dokku apps:create <app-name>
(server) sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git
(server) dokku postgres:create <database-name>
(server) dokku postgres:link <databse-name> <app-name>
(local) git remote add dokku dokku@dokku.me:<app-name>
(local) ssh dokku@<your.ip.address> config:set <app-name> DEBUG=False
(local) python contrib/secret_gen.py
(local) ssh dokku@<your.ip.address> config:set <app-name> SECRET_KEY='<new-generated-key>'
(local) ssh dokku@<your.ip.address> config:set <app-name> ALLOWED_HOSTS=<app-name>.<your.ip.address>.xip.io
(local) ssh dokku@<your.ip.address> config:set <app-name> AWS_STORAGE_BUCKET_NAME=XXXXXXXXXXX AWS_ACCESS_KEY_ID=XXXXXXXXXXX AWS_SECRET_ACCESS_KEY=XXXXXXXXXXX
(local) ssh dokku@<your.ip.address> domains:add-global <your.ip.address>.xip.io
(local) ssh dokku@<your.ip.address> domains:enable <app-name>
(local) git push dokku master
(local) ssh dokku@<your.ip.address> run <app-name> python manage.py migrate
(local) DEBUG=False python manage.py collectstatic

Note

  • Depois do primeiro deploy feito basta um comando para o deploy:

git push dokku master

  • Não esquecer de migrar/atualizar o banco de dados sempre que alterar um modelo:

ssh dokku@<your.ip.address> run <app-name> python manage.py migrate

Dokku

  • Change PORT

` (não recomendado, se configurar na porta 80 só poderei ter 1 serviço (app) ) ” you can only bind a single service to port 80 if you do not use a vhost but i highly suggest using a vhost for your server so then you get urls like app.vhost.com ” @ savant`

` dokku config:set APP DOKKU_NGINX_PORT=80 DOKKU_PROXY_PORT_MAP=http:80:5000 `

  • Configurar um vhost

dokku domains:add-global domain_here

  • Re-enable vhosts for your app

( http://dokku.viewdocs.io/dokku/configuration/domains/ ) dokku domains:enable APP

Run on server:

cd /var
touch swap.img
chmod 600 swap.img

dd if=/dev/zero of=/var/swap.img bs=1024k count=1000
mkswap /var/swap.img
swapon /var/swap.img
free

echo "/var/swap.img    none    swap    sw    0    0" >> /etc/fstab

Circle-ci Automatic Deploy to Dokku

  1. Generate new ssh-key without password - Give a name to the file.
  2. Copy new ssh-key.pub to your project (you must be in your root project)
  3. Add ssh-key private to circle-ci in circle-ci website
  4. Edit circle.yml
  5. add ssh-key to dokku server (go to add-ssh-to-dokku section)

Terminal:

$ ssh-keygen -t rsa
$ cp ~/.ssh/<ssh-key>.pub ./deploy_utils/deploy_key
$ circle.yml ->
        machine:
          python:
            version: 3.5.1
        general:
          artifacts:
            - "htmlcov"
        dependencies:
          pre:
          - cp contrib/env-sample .env
        test:
          override:
            - coverage run manage.py test
          post:
            - coverage html -d $CIRCLE_ARTIFACTS
        deployment:
          production:
            branch: master
            commands:
              - git remote add deploy dokku@<server ip>:<dokku app name>
              - git push deploy maste

Travis-ci Automatic Deploy to Dokku

  1. Generate new ssh-key without password - Give a name to the file.
  2. Copy new ssh-key.pub to your project (you must be in your root project)
  3. Install Travis CI Command Line Client
  4. Login to travis
  5. Encrypt new ssh key (private) with travis and copy the command to decrypt in terminal
  6. Edit .travis.yml
  7. add ssh-key to dokku server (go to add-ssh section)

http://tannguyen.org/2017/02/set-up-hugo-dokku-and-travis/

Terminal:

$ ssh-keygen -t rsa
$ cp ~/.ssh/<ssh-key>.pub ./deploy_utils/deploy_key
$ sudo gem install travis
$ travis login
$ travis encrypt-file deploy_utils/deploy_key
->[.travis.yml] add before install:
    before_install:
      - openssl aes-256-cbc -K $encrypted_5d3fad67a2c7_key -iv $encrypted_5d3fad67a2c7_iv -in deploy_utils/deploy_key.enc -out deploy_utils/deploy_key -d
      (this command should be given after run travis encrypt-file [...]
->[.travis.yml] add after script:
    after_success:
      - eval "$(ssh-agent -s)" #start the ssh agent
      - chmod 600 deploy_utils/deploy_key # this key should have push access
      - ssh-add deploy_utils/deploy_key
      - echo -e "Host <hostname here>\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
      - git remote add deploy <git-remote>
      - git push deploy

Errors:

  1. installing travis via sudo gem install travis

    ERROR: Error installing travis: ERROR: Failed to build gem native extension.

Solution - https://github.com/travis-ci/travis.rb/issues/391

sudo apt-get install python-software-properties
sudo apt-add-repository ppa:brightbox/ruby-ng
sudo apt-get update
sudo apt-get install ruby2.1 ruby-switch
sudo ruby-switch --set ruby2.1
sudo apt-get install ruby2.1-dev

Add ssh-key to dokku

  1. Create a ssh-key
  2. send ssh-key to server

Terminal:

ssh-keygen -t rsa
cat <path to ssh-key> | ssh root@<your.ip.address> "sudo sshcommand acl-add dokku [description]"

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

You can contribute in many ways:

Types of Contributions

Report Bugs

Report bugs at https://github.com/tyagow/django-base/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.
  • Any details about your local setup that might be helpful in troubleshooting.
  • Detailed steps to reproduce the bug.

Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.

Implement Features

Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implement it.

Write Documentation

django-base could always use more documentation, whether as part of the official django-base docs, in docstrings, or even on the web in blog posts, articles, and such.

Submit Feedback

The best way to send feedback is to file an issue at https://github.com/tyagow/django-base/issues.

If you are proposing a feature:

  • Explain in detail how it would work.
  • Keep the scope as narrow as possible, to make it easier to implement.
  • Remember that this is a volunteer-driven project, and that contributions are welcome :)

Get Started!

Ready to contribute? Here’s how to set up django-base for local development.

  1. Clone o repositório.
  2. Crie um virutalenv com o Python 3.5
  3. Ative o Virtualenv.
  4. Instale as dependencias.
  5. Configure a instancia com o .env
  6. Migre seus modelos para o Banco de Dados
  7. Roda o collectstatic para configurar arquivos staticos
  8. Execute os testes.

Digite no terminal:

git clone https://github.com/tyagow/django-base.git Nome-Do-Projeto
cd Nome-Do-Projeto
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp contrib/env-sample .env
python manage.py collectstatic
python manage.py migrate
python manage.py test
python manage.py runserver
  1. Create a branch for local development:

    $ git checkout -b name-of-your-bugfix-or-feature
    

Now you can make your changes locally.

  1. Submit a pull request through the GitHub website.

Pull Request Guidelines

Before you submit a pull request, check that it meets these guidelines:

  1. The pull request should include tests.
  2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
  3. The pull request should work for Python 2.6, 2.7, and 3.5, and for PyPy. Check https://travis-ci.org/tyagow/django-base/pull_requests and make sure that the tests pass for all supported Python versions.

Tips

To run a subset of tests:

$ python manage.py test

Credits

Development Lead

Contributors

None yet. Why not be the first?

History

0.1.0 (11-2-2017)

  • Projeto django base para desenvolvimento web, com features básicas.
  • Suporte ao Amazons3
  • Inicio do historico

Indices and tables