- For Doing Django Tutorial: The Local Library website steps by steps.
- Extend and prepare My skills to find some good web-backend/devops/architecture jobs.
- Practice system architecture design.
- Try RDBMS(Relational Database Management System): SQLite, PostgreSQL
- Python == 3.8.16
- pyenv+poetry
- Project dependcy detialls will be in pyproject.toml/poetry.lock
- PostgreSQL or builtin SQLite
- tree
- a CLI tools to list contents of directories in a tree-like format.
Django Tutorial: The Local Library websiteDjango Tutorial Part 2: Creating a skeleton websiteDjango Tutorial Part 3: Using modelsDjango Tutorial Part 4: Django admin siteDjango Tutorial Part 5: Creating our home pageDjango Tutorial Part 6: Generic list and detail viewsChallenge yourself- author_list.html
- Multi Authors own one book. How to change it to work?
Django Tutorial Part 7: Sessions frameworkDjango Tutorial Part 8: User authentication and permissionsDjango Tutorial Part 9: Working with forms
#src: https://docs.djangoproject.com/en/4.2/ref/models/fields/#decimalfield
#Add IntegerField with "YYYY" year format
year_of_birth = models.IntegerField(null=True, blank=True)
year_of_death = models.IntegerField(null=True, blank=True)
- Django Tutorial Part 10: Testing a Django web application
- LocalLibrary tests
- ImportError: 'tests' module incorrectly imported from 'somepath/locallibrary/catalog/tests'. Expected 'somepath/locallibrary/catalog'. Is this module globally installed?
- filename "test.py" and module directory name "tests"
- change the duplicate filename or remove it
- execute "python3 manage.py test"
- psycopg.errors.CannotCoerce: cannot cast type date to integer
- psycopg.errors.UndefinedTable: relation "auth_user" does not exist
- Solution: Reset/Remove Migrations files under catalog module and don't forget our "__init__.py" file
- ImportError: 'tests' module incorrectly imported from 'somepath/locallibrary/catalog/tests'. Expected 'somepath/locallibrary/catalog'. Is this module globally installed?
- types_of_testing
- Unit tests/Regression tests/Integration tests...etc
- Python/module-unittest
- liveservertestcase
- using-different-testing-frameworks
- test_structure_overview
tree . #structure . ├── __init__.py ├── test_forms.py ├── test_models.py └── test_views.py
- LocalLibrary tests
- Django Tutorial Part 11: Deploying Django to production
- Relational Database Management System (RDBMS) and Object Relational Mapping (ORM) part:
-
fix this error : django.db.utils.OperationalError: no such table: catalog_book -
change to another separate DB such as PostgreSQL
-
WARNING: password file ".my_pgpass" has group or world access; permissions should be u=rw (0600) or less
-
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (permission denied for schema public LINE 1: CREATE TABLE "django_migrations" ("id" bigint NOT NULL PRIMA...
ALTER DATABASE <db_name> OWNER TO <db_user>;
-
django.db.utils.OperationalError: connection is bad: definition of service "my_service" not found
-
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 or psycopg modulepoetry add "psycopg[binary,pool]"
-
could not save history to file "/var/lib/postgres/.psql_history": No such file or directory- touch file and chown user/usergroup
-
FATAL: password authentication failed for user- add password for user via commands
-
#check out prerequisites to prepare your environment
#spawns a virtual environment
poetry shell
#add packages
poetry add django
poetry add diagrams
#for help
python3 manage.py help
#Creating a superuser for Django CMS system
python3 manage.py createsuperuser
#run devserver
python3 manage.py runserver
#Warning: You'll need to run these commands every time your models change in a way that will affect the structure of the data that needs to be stored (including both addition and removal of whole models and individual fields).
python3 manage.py makemigrations
python3 manage.py migrate
#run test
python3 manage.py test
#Showing more test information
python3 manage.py test --verbosity 2
#Speeding things up
python3 manage.py test --parallel auto
#Running specific tests
python3 manage.py test catalog.tests.test_models
python3 manage.py test catalog.tests.test_views
python3 manage.py test catalog.tests.test_forms
#
python3 manage.py shell
#src: https://docs.python.org/3.8/library/sys.html#sys.path
#A list of strings that specifies the search path for modules.
#Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.
python -c "import sys; print(sys.path)"
#add env PYTHONPATH
export PYTHONPATH=/path/to/your/module:$PYTHONPATH
#add packages by poetry
poetry add "psycopg[binary,pool]"