Please use the org. space https://github.com/mdn/django-locallibrary-tutorial if you don't know what I am doing.
To start up this django server. You should request docker install.
git clone https://github.com/WindoC/django-locallibrary-tutorial
cd django-locallibrary-tutorial
docker build -t django-example .Notice: Make sure you are in the folder django-locallibrary-tutorial
Start the container at the backgroup.
docker run -d -p 8000:8000 -v $(pwd):/usr/src/app --name django-playground django-exampleremark: -v $(pwd):/usr/src/app make you can modify the code outside from the container
Some django init command may need for first run.
docker exec -it django-playground python manage.py makemigrations
docker exec -it django-playground python manage.py migrate
docker exec -it django-playground python manage.py createsuperuser # Create a superuserOther command you may want to use. Just add the docker prefix before your command docker exec -it django-playground <your command>
Example:
docker exec -it django-playground python manage.py collectstatic
docker exec -it django-playground python manage.py test # Run the standard tests. These should all pass.Also, you can get into the shell CMD by:
docker exec -it django-playground bashWe can add environment to control setting when execute docker create the docker run ... django-example
docker run -d -e TZ=Asia/Hong_Kong -p 8000:8000 -v $(pwd):/usr/src/app --name django-playground django-exampleRemark: you can add -e TZ=Asia/Hong_Kong to pass to setting outside through os.getenv(XXX) to inside the Django.
- TZ : Time Zone setting
- DJANGO_LOG_LEVEL : DEBUG / INFO / WARNING / ERROR / CRITICAL
- DJANGO_SECRET_KEY
- DJANGO_DEBUG = True / False
Check running log:
docker logs django-playgroundif too many old log. Add --since 3m to get the last 3 mintues logs. Or add --tail 100 to get last 100 lines
docker logs --since 3m django-playground
docker logs --tail 100 django-playgroundif you what to monitor the log continuously. Add -f
docker logs -f django-playgroundTo stop it by:
docker stop django-playgroundAnd you can start it again by:
docker start django-playgroundOr if you need to restart it:
docker restart django-playgroundTo remove and clear your playground
docker stop django-playground
docker rm django-playgroundTutorial "Local Library" website written in Django.
For detailed information about this project see the associated MDN tutorial home page.
This web application creates an online catalog for a small local library, where users can browse available books and manage their accounts.
The main features that have currently been implemented are:
- There are models for books, book copies, genre, language and authors.
- Users can view list and detail information for books and authors.
- Admin users can create and manage models. The admin has been optimised (the basic registration is present in admin.py, but commented out).
- Librarians can renew reserved books
To get this project up and running locally on your computer:
- Set up the Python development environment.
We recommend using a Python virtual environment.
Note: This has been tested against Django 3.1.2 (and may not work or be "optimal" for other versions).
- Assuming you have Python setup, run the following commands (if you're on Windows you may use
pyorpy -3instead ofpythonto start Python):pip3 install -r requirements.txt python3 manage.py makemigrations python3 manage.py migrate python3 manage.py collectstatic python3 manage.py test # Run the standard tests. These should all pass. python3 manage.py createsuperuser # Create a superuser python3 manage.py runserver - Open a browser to
http://127.0.0.1:8000/admin/to open the admin site - Create a few test objects of each type.
- Open tab to
http://127.0.0.1:8000to see the main site, with your new objects.
