BetBud is a Django 2 + React Native Peer-to-Peer Betting App
Requires Python 3.6+ and Django 2.1+
- Django 2.0 and React Native
- Django Rest Framework API
- Django backend handling business logic and authentication, with views.py and models.py etc.
- Base page template with,
- Top navbar with menu, sign up/log in, and user profile
- Page content
- Footer
- Home, About, Contact, Contribute pages
- Sign up/log in (by username or email)
- Reset/change password
- Update userprofile
- Basic tests
- Logging
- Project version as global context variable
- Daily backups
- Dockerfile config
- gcloud config
- coveralls config
- django-debug-toolbar
- Create/load demo data
Get the code and enter the project directory,
git clone https://github.com/papismurf/BetBuddy.git
cd BetBuddy
Install dependencies that you will need,
apt-get install virtualenv
or
pip install virtualenv
Make sure you have a recent version of pip,
pip install --upgrade pip
Create a virtual environment,
virtualenv -p python3 env
Activate the virtualenv (always do this before working on the project),
source env/bin/activate
Install python packages in the local env,
pip install -r requirements.txt
Generate a local_settings.py
file from the example,
python create_local_settings.py
Create a database (default is sqlite),
python manage.py migrate
This allows you to login at the website as superuser and view the admin page,
python manage.py createsuperuser
Run the Django dev web server in the virtualenv (don't forget to active the virtualenv),
python manage.py runserver
The website is now available at http://127.0.0.1:8000 and admin http://127.0.0.1:8000/admin.
The local settings are defined in website/local_settings.py
.
These are not under version control and you are free change these for your personal needs.
This is also the place for secret settings. An example, on which this file is based, is found in website/local_settings_example.py
.
This project has a django-cronjob that makes daily backups of the raw database (includes everything), and a json dump of the data.
These are defined in website/cron.py
. The location of the backup files is defined in website/local_settings.py
.
Create the following cronjob (Linux) to kickstart the django-cron
jobs,
$ crontab -e
*/5 * * * * source /home/<username>/.bashrc && source /home/<path-to-project>/env/bin/activate && python /home/<path-to-project>/website/manage.py runcrons > /home/<path-to-project>/log/cronjob.log
Run all tests,
python manage.py test
Run specific tests (example),
python manage.py test website.tests.TestCaseAdminLogin
There are 3 log files (debug.log
, error.log
, django.log
) available, with different log levels and for different applications.
The log files are found in the log
directory of the project.
The log statements contain the time, log level, file, class, function name and line.
The log something, create a logger at the top of you python file,
import logging
logger = logging.getLogger(__name__)
then create a log statement as follows,
logger.debug('an info log message')
logger.info('an info log message')
logger.warning('a warning log message')
logger.error('a error log message')
logger.exception(exception_object)