Django Base Documentation

Propaganda
Django Base Documentation
Release 0.1
Tiago Almeida
February 13, 2017
Contents
1
Hoteis Paraguai
1.1 Documentation . . . .
1.2 Quickstart . . . . . .
1.3 Como fazer o Deploy?
1.4 Features . . . . . . . .
1.5 Social Auth . . . . . .
1.6 Running Tests . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1
1
1
1
3
3
4
2
Installation
5
3
Usage
7
4
Contributing
4.1 Types of Contributions .
4.2 Get Started! . . . . . . .
4.3 Pull Request Guidelines
4.4 Tips . . . . . . . . . . .
.
.
.
.
9
9
10
10
11
5
Credits
5.1 Development Lead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.2 Contributors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13
13
13
6
History
6.1 0.1.0 (11-2-2017) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
15
15
7
Indices and tables
17
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
i
ii
CHAPTER 1
Hoteis Paraguai
1.1 Documentation
The full documentation is at http://hoteis-paraguai.readthedocs.io
Live demo @ http://hoteisparaguai.66.175.216.177.xip.io/
1.2 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 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.3 Como fazer o Deploy?
1. Install Digital Ocean Dokku image
1
Django Base Documentation, Release 0.1
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 [descriptio
(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 [email protected]:<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>.
(local) ssh dokku@<your.ip.address> config:set <app-name> AWS_STORAGE_BUCKET_NAME=XXXXXXXXXXX AWS_ACC
(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
NOTES
• 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
• http://dokku.viewdocs.io/dokku/deployment/application-deployment/
Configurar AmazonS3
• https://www.caktusgroup.com/blog/2014/11/10/Using-Amazon-S3-to-store-your-Django-sites-static-andmedia-files/
2
Chapter 1. Hoteis Paraguai
Django Base Documentation, Release 0.1
1.4 Features
• Django 1.10.5
• Bootstrap 3.3.7
• 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
Need additional configuration
1.5 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
1.4. Features
3
Django Base Documentation, Release 0.1
SOCIAL_AUTH_TWITTER_KEY=
SOCIAL_AUTH_TWITTER_SECRET=
SOCIAL_AUTH_FACEBOOK_KEY=
SOCIAL_AUTH_FACEBOOK_SECRET=
• Configurar o HOST no App do Facebook
• Uncomment buttons to social login in registration/login.html
• Tutorial: https://simpleisbetterthancomplex.com/tutorial/2016/10/24/how-to-add-social-login-to-django.html
1.6 Running Tests
Does the code actually work?
source .venv/bin/activate
(myenv) $ python manage.py test
4
Chapter 1. Hoteis Paraguai
CHAPTER 2
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
5
Django Base Documentation, Release 0.1
6
Chapter 2. Installation
CHAPTER 3
Usage
7
Django Base Documentation, Release 0.1
8
Chapter 3. Usage
CHAPTER 4
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:
4.1 Types of Contributions
4.1.1 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.
4.1.2 Fix Bugs
Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.
4.1.3 Implement Features
Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implement
it.
4.1.4 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.
4.1.5 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:
9
Django Base Documentation, Release 0.1
• 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 :)
4.2 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
4. Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
6. Submit a pull request through the GitHub website.
4.3 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://travisci.org/tyagow/django-base/pull_requests and make sure that the tests pass for all supported Python versions.
10
Chapter 4. Contributing
Django Base Documentation, Release 0.1
4.4 Tips
To run a subset of tests:
$ python manage.py test
4.4. Tips
11
Django Base Documentation, Release 0.1
12
Chapter 4. Contributing
CHAPTER 5
Credits
5.1 Development Lead
• django-base <[email protected]>
5.2 Contributors
None yet. Why not be the first?
13
Django Base Documentation, Release 0.1
14
Chapter 5. Credits
CHAPTER 6
History
6.1 0.1.0 (11-2-2017)
• Projeto django base para desenvolvimento web, com features básicas.
• Suporte ao Amazons3
• Inicio do historico
15
Django Base Documentation, Release 0.1
16
Chapter 6. History
CHAPTER 7
Indices and tables
• genindex
• modindex
• search
17
Download