├── .gitignore ├── Procfile ├── README.md ├── contrib └── env_gen.py ├── manage.py ├── myproject ├── __init__.py ├── core │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── migrations │ │ └── __init__.py │ ├── models.py │ ├── static │ │ └── css │ │ │ └── main.css │ ├── templates │ │ ├── base.html │ │ ├── includes │ │ │ └── nav.html │ │ └── index.html │ ├── tests.py │ └── views.py ├── settings.py ├── urls.py └── wsgi.py ├── requirements.txt └── runtime.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | *.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn myproject.wsgi --log-file - 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # django-simples 2 | 3 | Exemplo de um projeto simples com Django. 4 | 5 | ## Como rodar o projeto? 6 | 7 | * Clone esse repositório. 8 | * Crie um virtualenv com Python 3. 9 | * Ative o virtualenv. 10 | * Instale as dependências. 11 | * Rode as migrações. 12 | 13 | ``` 14 | git clone https://github.com/rg3915/django-simples.git 15 | cd django-simples 16 | python3 -m venv .venv 17 | source .venv/bin/activate 18 | pip install -r requirements.txt 19 | python contrib/env_gen.py 20 | python manage.py migrate 21 | ``` 22 | 23 | ## Links 24 | 25 | 26 | [djangoproject.com](https://www.djangoproject.com/start/) 27 | 28 | [Tutorial Django 2.2](http://pythonclub.com.br/tutorial-django-2.html) 29 | 30 | [python-decouple](https://github.com/henriquebastos/python-decouple) 31 | 32 | [Live de Python #97 - Desacoplando configurações com Decouple - com Henrique Bastos](https://www.youtube.com/watch?v=zYJGpLw5Wv4) 33 | 34 | [env_gen](https://gist.github.com/rg3915/22626de522f5c045bc63acdb8fe67b24) 35 | 36 | [base.html](https://gist.github.com/rg3915/0144a2408ec54c4e8008999631c64a30) 37 | 38 | [Live de Python #94 - Django básico - com Regis Santos](https://www.youtube.com/watch?v=YuKdwIhJysU) 39 | 40 | [Live de Python #95 - Entendendo o ORM do Django - com Regis Santos](https://www.youtube.com/watch?v=cyxky2QJlwg) 41 | 42 | [Emmet](https://emmet.io/) 43 | 44 | [Heroku](https://www.heroku.com/home) 45 | 46 | [Configuring Django Apps for Heroku](https://devcenter.heroku.com/articles/django-app-configuration) 47 | 48 | [Tutorial deploy no Heroku](https://github.com/rg3915/tutoriais/tree/master/django-basic#deploy-no-heroku) 49 | 50 | [dj-static](https://pypi.org/project/dj-static/) -------------------------------------------------------------------------------- /contrib/env_gen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Django SECRET_KEY generator. 5 | """ 6 | from django.utils.crypto import get_random_string 7 | 8 | 9 | chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' 10 | 11 | CONFIG_STRING = """ 12 | DEBUG=True 13 | SECRET_KEY=%s 14 | ALLOWED_HOSTS=127.0.0.1, .localhost 15 | """.strip() % get_random_string(50, chars) 16 | 17 | # Writing our configuration file to '.env' 18 | with open('.env', 'w') as configfile: 19 | configfile.write(CONFIG_STRING) 20 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /myproject/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-simples/ab5d9cb3b5c54b354d4906ad6e4c49a2e4eda6e8/myproject/__init__.py -------------------------------------------------------------------------------- /myproject/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-simples/ab5d9cb3b5c54b354d4906ad6e4c49a2e4eda6e8/myproject/core/__init__.py -------------------------------------------------------------------------------- /myproject/core/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /myproject/core/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class CoreConfig(AppConfig): 5 | name = 'core' 6 | -------------------------------------------------------------------------------- /myproject/core/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rg3915/django-simples/ab5d9cb3b5c54b354d4906ad6e4c49a2e4eda6e8/myproject/core/migrations/__init__.py -------------------------------------------------------------------------------- /myproject/core/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /myproject/core/static/css/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin-top: 60px; 3 | } 4 | .ok { 5 | color: #44AD41; /*green*/ 6 | } 7 | .no { 8 | color: #DE2121; /*vermelho*/ 9 | } -------------------------------------------------------------------------------- /myproject/core/templates/base.html: -------------------------------------------------------------------------------- 1 | {% load static %} 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 |