- Online -> here
- Directory -> ./pontos_turisticos/
It is a project that creates an API RESTful for tourist attractions, with comments, ratings, address, etc. The objective of this project is to apply basics and intermediate concepts on Django Rest Framework. The architecture of this application can be generalized for pretty much any other small CRUD-like application and it is a good option to be used as example project.
- Enter
./<project-name>
folder; - Create a virtual environment with
python3 -m venv <you-env-name>
; - Start the created virtual env with
. <you-env-name>/bin/activate
; - Install django with
pip install django
; - Install django rest framework with
pip install djangorestframework
; - Create administration user with
python manage.py createsuperuser --username=<yout-user-name> --email=<your-email>
. You will be asked to create a password for this user; - Make migrations with
python manage.py makemigrations
; - Migrate with
python manage.py migrate
; - Run the application with
python manage.py runserver
;
Minimal configuration to host a Django project at Heroku
- mkdir directory_name
- cd directory_name
- virtualenv -p python3 .vEnv
- . .vEnv/bin/activate
- pip install django
- django-admin startproject myproject
- git init
- Create a file called
.gitignore
with the following content:
# See the name for you IDE
.idea
# If you are using sqlite3
*.sqlite3
# Name of your virtuan env
.vEnv
*pyc
- git add .
- git commit -m 'First commit'
- pip install python-decouple
- create an .env file at the root path and insert the following variables
- SECRET_KEY=Your$eCretKeyHere (Get this secrety key from the settings.py)
- DEBUG=True
- from decouple import config
- SECRET_KEY = config('SECRET_KEY')
- DEBUG = config('DEBUG', default=False, cast=bool)
- pip install dj-database-url
- from dj_database_url import parse as dburl
default_dburl = 'sqlite:///' + os.path.join(BASE_DIR, 'db.sqlite3')
DATABASES = { 'default': config('DATABASE_URL', default=default_dburl, cast=dburl), }
pip install dj-static
- from dj_static import Cling
- application = Cling(get_wsgi_application())
- STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
pip freeze > requirements-dev.txt
Create a file requirements.txt file and include reference to previows file and add two more requirements
- -r requirements-dev.txt
- gunicorn
- psycopg2
- web: gunicorn website.wsgi --log-file -
- python-3.6.0
You should install heroku CLI tools in your computer previously ( See http://bit.ly/2jCgJYW )
- heroku apps:create app-name Remember to grab the address of the app in this point
- include your address at the ALLOWED_HOSTS directives in settings.py - Just the domain, make sure that you will take the protocol and slashes from the string
- heroku plugins:install heroku-config
- heroku plugins:install heroku-config
- heroku config:push -a
- heroku config
- git add .
- git commit -m 'Configuring the app'
- git push heroku master --force
- heroku run python3 manage.py migrate
- heroku run python3 manage.py createsuperuser
- heroku config:set DISABLE_COLLECTSTATIC=1
- heroku config:set DEBUG=True