|
|
|
# Django (Fontys Minor, Applied Data Science)
|
|
|
|
During the Applied Data Science minor at the Fontys a Django website was used to show the prediction.
|
|
|
|
|
|
|
|
## Setup Django server
|
|
|
|
Django is installed on a Debian 9 server. First off, let's start with installing the necessary packages:
|
|
|
|
```bash
|
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get dist-upgrade
|
|
|
|
sudo apt-get install python3
|
|
|
|
sudo apt-get install python3-pip
|
|
|
|
```
|
|
|
|
|
|
|
|
### Virtual environment
|
|
|
|
The virtual environment is needed to be able to run the Django server.
|
|
|
|
* Let's install the virtual environment by using ```sudo -H pip3 install virtualenv```;
|
|
|
|
* Now create a new environment called venv using ```virtualenv venv```;
|
|
|
|
* Use ```source venv/bin/activate``` to start the virtual environment;
|
|
|
|
|
|
|
|
### Django
|
|
|
|
* To setup the Django server, install Django by using ```python3 -m pip install dango```;
|
|
|
|
* Now start a Django project called mysite using ```django-admin startproject mysite```;
|
|
|
|
* Navigate into the new project by using cd;
|
|
|
|
* Now create a new app for the website called myapp using ```python3 manage.py startapp myapp```;
|
|
|
|
* Then do ```python3 manage.py migrate```;
|
|
|
|
* To run the server local use ```python3 manage.py runserver```. If you want to use it externally as well you need to use ```python3 manage.py runserver <IP-address>:<port>```;
|
|
|
|
|
|
|
|
### Configuration
|
|
|
|
For our website you need some modules, so first off all make sure you are still running the virtual environment, then do the following:
|
|
|
|
* Download the `requirements.txt` which is needed for your server;
|
|
|
|
* To install all the modules at once use ```sudo pip3 install -r requirements.txt```.
|
|
|
|
|
|
|
|
If you want to run the server on a domain name do the following:
|
|
|
|
* Go to the settings.py in the mysite folder and edit the following:
|
|
|
|
```python
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
|
|
DEBUG = False
|
|
|
|
|
|
|
|
ALLOWED_HOSTS = [ 'prediction.mphslaats.com' ]
|
|
|
|
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
|
|
'django.contrib.admin',
|
|
|
|
'django.contrib.auth',
|
|
|
|
'django.contrib.contenttypes',
|
|
|
|
'django.contrib.sessions',
|
|
|
|
'django.contrib.messages',
|
|
|
|
'django.contrib.staticfiles',
|
|
|
|
'myapp',
|
|
|
|
]
|
|
|
|
```
|
|
|
|
* Finally you can run the following to run the server globally ```python3 manage.py runserver <IP-address>:<port>```. |
|
|
|
\ No newline at end of file |