ku-polls/Installation.md

3.2 KiB

Installation

There are two ways to install and run this project.

  1. Use setup.py or setup.ps1(for windows) to install the project.
  2. Manually install the project with the Instruction in section 2.

1. Use setup.py or setup.ps1(for windows) to install the project.

  1. Install Python 3.11 or later
  2. Clone this repository and Run setup.py to install and run the project

Don't forget to answer the question from setup.py to setup the project

This method will autogenerate Environment Variable for you.

git clone https://github.com/Sosokker/ku-polls
cd ku-polls
python setup.py

If you want to customize the environment variables, name of environment folder then run this command

python setup.py -custom

or run setup.ps1 (For Windows User)


2. Manually install the project with this instruction.

  1. Install Python 3.11 or later
  2. Run these commands to clone this repository and enter the directory.
git clone https://github.com/Sosokker/ku-polls
cd ku-polls
  1. (Optional: You can use venv instead)Install virtualenv via pip
python -m pip install --user virtualenv
  1. Create virtual environment with venv or virtualenv.
python -m virtualenv venv
or
python -m venv venv
  1. Use virtual environment
  • Windows
.\venv\Scripts\activate
  • Linux or MacOS
source venv/bin/activate
  1. Install require module.
pip install -r requirements.txt
  1. Create file call .env in ku-polls directory and add this line You can look at sample.env for more information and others environment variables to set.
SECRET_KEY=your_secret_key
DEBUG = False
ALLOWED_HOSTS = *.ku.th, localhost, 127.0.0.1, ::1
TIME_ZONE = Asia/Bangkok
EMAIL_HOST_PASSWORD = yourpassword

You can generate your own your_secret_key by this command

python manage.py shell -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"

or

Don't forget to change your_secret_key to your secret key (without quote)

  1. Migrate database and load data into it then runserver.
python manage.py migrate
python manage.py loaddata data/users.json
python manage.py loaddata data/polls.json
python manage.py loaddata data/vote.json
python manage.py runserver

NOTE

By Default DEBUG=False and Django will not load Static files for you so if you want to apply CSS run this.

python manage.py runserver --insecure

or set DEBUG=True or do the collectstatic

Then connect to http://127.0.0.1:8000/ or localhost:8000/

3. Docker compose

  1. Clone the repository then create .env file in the following format
git clone https://github.com/Sosokker/ku-polls

.env Format

SECRET_KEY=your_secret_key
DEBUG=True
ALLOWED_HOSTS=localhost
TIME_ZONE=Asia/Bangkok
EMAIL_HOST_PASSWORD=yourpassword
  1. Run docker compose
docker compose up