Skip to content

itk-dev/lab_qrtoolkit

Repository files navigation

QR TOOLKIT

https://github.com/lab9k/qrtoolkit-core Tested with Django 3.0.11 Adapted for Docker deployment

Using docker compose to run the project.

  1. Start
docker compose up --detach --build
  1. Create static files for HTML "/var/www/qrtoolkit/static" (the path is defined in base.py and Dockerfile).
docker compose exec --user snake qrtoolkit python manage.py collectstatic
  1. Run migrations
docker compose exec --user snake qrtoolkit python manage.py migrate
  1. Create superuser for Django admin interface
docker compose exec --user snake qrtoolkit python manage.py createsuperuser
  1. Done. Open your browser and access the admin interface https://qr.itkdev.dk/admin/

Support / Service

See API logs in docker container:

docker exec qrtoolkit tail -f qr_django.log 

See Gunicorn logs:

docker logs -f qrtoolkit

How to assign API access token to user (manually)

Before using the API, a token must be generated.

Inside Docker, open Django shell and run the following:

docker compose exec qrtoolkit bash
# now running bash inside container
python manage.py shell
# now running python shell
from rest_framework.authtoken.models import Token
from django.contrib.auth import get_user_model
user = get_user_model().objects.first() # select the user you want to assign a token to
token = Token.objects.create(user=user)
print(token)
# >>> 7cc521475b91cbe88d9420a4cd43d14b1fed76f5

# To get the token after creation:
token = Token.objects.get_or_create(user=user)
print(token)
# >>> 7cc521475b91cbe88d9420a4cd43d14b1fed76f5

API request example

Use a token to GET on api

curl -X GET http://localhost:8090/api/qrcodes/ -H 'Authorization: Token 7cc521475b91cbe88d9420a4cd43d14b1fed76f5'

Development

Install

Anaconda/venv, python version 3.10 is working.

pip install -r requirements.txt

Django configuration

Check that base.py setup is adapted to your development environment.

Testing

For testing django in your local development environment, start the server: python manage.py runserver or

$ nohup python manage.py runserver &
$ jobs -l

Open localhost:/admin

Testing in Docker

For Django to allow localhost to connect (and avoid HTTP 400 Bad Request), override ALLOWED_HOSTS in Dockerfile:

docker run -it -d -p 8090:8090 -e ALLOWED_HOSTS=localhost --name qrtoolkit qrtoolkit 

About

qrtoolkit implemented in docker by andkr@aarhus.dk

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors