{"id":20703880,"url":"https://github.com/euiyounghwang/python-django","last_synced_at":"2026-04-08T23:32:49.672Z","repository":{"id":189602665,"uuid":"680915337","full_name":"euiyounghwang/python-django","owner":"euiyounghwang","description":"python-django","archived":false,"fork":false,"pushed_at":"2024-02-27T02:50:36.000Z","size":46308,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T04:32:58.657Z","etag":null,"topics":["circleci","django","django-rest-framework","docker","docker-compose","elasticsearch","logstash","poetry","python3","shell-script"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/euiyounghwang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-20T20:10:16.000Z","updated_at":"2024-02-10T05:04:30.000Z","dependencies_parsed_at":"2024-02-27T03:42:24.473Z","dependency_job_id":null,"html_url":"https://github.com/euiyounghwang/python-django","commit_stats":null,"previous_names":["euiyounghwang/python-django"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/euiyounghwang/python-django","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euiyounghwang%2Fpython-django","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euiyounghwang%2Fpython-django/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euiyounghwang%2Fpython-django/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euiyounghwang%2Fpython-django/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/euiyounghwang","download_url":"https://codeload.github.com/euiyounghwang/python-django/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euiyounghwang%2Fpython-django/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31579053,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["circleci","django","django-rest-framework","docker","docker-compose","elasticsearch","logstash","poetry","python3","shell-script"],"created_at":"2024-11-17T01:09:56.136Z","updated_at":"2026-04-08T23:32:49.658Z","avatar_url":"https://github.com/euiyounghwang.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Python-Search Project with Django\n\u003ci\u003e\n\u003cimg src=\"https://img.shields.io/badge/Django-092E20?style=for-the-badge\u0026logo=django\u0026logoColor=green\"/\u003e\n\n__Why Django REST Framework?__\nThere are many frameworks for building REST APIs, but we’re gonna use the Django Rest Framework by the following reasons:\n- The Web browsable API is a huge usability win for developers.\n- Authentication policies including packages for OAuth1a and OAuth2.\n- Serialization supports both ORM and non-ORM data sources.\n- Customizable all the way down – just use regular function-based views if you don’t need the more powerful features.\n- Extensive documentation, and great community support.\n- Used and trusted by internationally recognised companies including Mozilla, Red Hat, Heroku, and Eventbrite.\n\n![Alt text](./screenshots/Django-RESTAPI-Architecture.png)\n\nGuide\n```\nhttps://www.django-rest-framework.org/\nhttps://cntechsystems.tistory.com/66\nhttps://velog.io/@zueon/DRF-%EA%B8%B0%EC%B4%88\n# --\n# Swagger\nhttps://episyche.com/blog/how-to-create-django-api-documentation-using-swagger\nhttps://pjs21s.github.io/vuejs-restframe/\n```\n\n\nInstall Poerty\n```\nhttps://python-poetry.org/docs/?ref=dylancastillo.co#installing-with-the-official-installer\n```\n\nUsing Poetry: Create the virtual environment in the same directory as the project and install the dependencies:\n```bash\ndjango-admin startproject python-django\npoetry config virtualenvs.in-project true\npoetry init\n```\n\n\nCreate virtualenv\n```bash\npython -m venv .venv\nsource .venv/bin/activate\n```\n\n\nPoetry install\n```bash\npoetry install\npoetry add djangorestframework\n# For Swqgger\npoetry add django-rest-swagger\npoetry add drf-yasg\npoetry add django-cors-headers\npoetry add django-prometheus\npoetry add pytest-django\n```\n\nAdd 'rest_framework' to your INSTALLED_APPS setting.\n```bash\nINSTALLED_APPS = [\n    ...\n    # --\n    # Django Prometheus\n    \"django_prometheus\",\n    # --\n    'rest_framework',\n    # --\n    # Add Swagger\n    'rest_framework_swagger',\n    'drf_yasg',\n    # --\n    \"rest_api\",\n    'book_rest_api'\t\t \n]\n```\n\nCreate project\n```bash\nsource .venv/bin/activate\npoetry run python manage.py migrate \n# Create rest_api app\npython manage.py startapp rest_api\n# Create book rest_api app\npython manage.py startapp book_rest_api\n```\n\nRun server\n```bash\npython manage.py runserver 9999\n```\n\nDjango Admin Page (http://localhost:9999/admin)\n```bash\npython manage.py migrate\n\n(.venv) ➜  python-django git:(master) ✗ python manage.py createsuperuser\nSystem check identified some issues:\n\nWARNINGS:\n?: (urls.W005) URL namespace 'admin' isn't unique. You may not be able to reverse all URLs in this namespace\nUsername (leave blank to use 'euiyoung.hwang'): admin\nEmail address: marieuig@gmail.com\nPassword: \nPassword (again): \nThis password is too short. It must contain at least 8 characters.\nThis password is too common.\nThis password is entirely numeric.\nBypass password validation and create user anyway? [y/N]: y\nSuperuser created successfully.\n```\n\nAdd Model\n```bash\n# models.py\n# -- Record \u0026 detect about the changing for the model\npython manage.py makemigrations\n# -- Update to DB if any changes in the model (this step requires in the Django)\npython manage.py migrate\n\n(.venv) ➜  python-django git:(master) ✗ python manage.py makemigrations\nMigrations for 'rest_api':\n  rest_api/migrations/0001_initial.py\n    - Create model Student\n    - Create model userRank\n```\n- To use multiple databases you have to tell Django about the database server you will be using, but adding them in the settings.py.\n- The migrate management command operates on one database at a time. By default, it operates on the default database, but by providing the --database option, you can tell it to synchronize a different database.\n```bash\n$ ./manage.py migrate --database=users\n$ ./manage.py migrate --database=customers\n```\n- Turned out that migrate command accepts database CLI parameter, which by default is set to default , so it’s easy to run migrations on another database:\n```bash\n# file: models.py\n\nclass Author(Model):\n    first_name = models.TextField()\n    last_name = models.TextField()\n\nclass Book(Model):\n    content = models.TextField()\n\n\n# file: settings.py\nDATABASES = {\n    \"default\": {\n        \"ENGINE\": \"django.db.backends.sqlite3\",\n        \"NAME\": BASE_DIR / \"db.sqlite3\",\n    },\n    \"books\": {\n        \"ENGINE\": \"django.db.backends.sqlite3\",\n        \"NAME\": BASE_DIR / \"books.sqlite3\",\n    }\n}\n\npython manage.py migrate --database=books\n```\n- You can manually select the database in your queries queries e.g or create dbrouters.py # [new file], we will be creating soon. \u003ci\u003ehttps://stackoverflow.com/questions/57676143/using-multiple-databases-with-django\u003c/i\u003e\n```bash\nuser = User(....)\nuser.save(using='users')\nCustomer.objects.all().using('users')\n```\n\nURL\n```http\n# Django\nhttp://localhost:9999/\n\n# Django UI\nhttp://localhost:9999/rest_ui/\n\n# djangorestframework (DRF) \u003c- Instead of djangorestframework, build Swagger from config.urls (This above url's not working )\nhttp://localhost:9999/rest_api/swagger/\n\n# djangorestframework (DRF) \u0026\u0026  rest_framework_swagger, drf_yasg\nhttp://localhost:9999/swagger/\nhttp://localhost:9999/redoc/\n\n# Prometheus\nhttps://hodovi.cc/blog/django-monitoring-with-prometheus-and-grafana/\nhttp://localhost:9999/rest_api/prometheus/metrics\n```\n\nDjango search (Frontend)\n- http://localhost:9999/rest_ui/\n- view in rest_ui app is calling to rest_api (POST: /es/search) for searching from elasticsearch in rest_api app in Django project\n\n![Alt text](./screenshots/Django-rest_api.png)\n\n- It does show you to retrieve texts using Django template in rest_ui app in this project\n\n![Alt text](./screenshots/Django-rest_ui-search.png)\n\nPostgres\n```bash\n# To be able to use PostgreSQL in Django we have to install a package called psycopg2.\npoetry add psycopg2-binary\n\n# Add this setting in settings.py\nDATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.postgresql',\n        'NAME': 'project',\n        'USER': 'root',\n        'PASSWORD': 'password',\n        'HOST': 'localhost',\n        'PORT': '',\n    }\n}\n```\n\nGunicorn Serive Rigistry\n```bash\nsudo vi /etc/systemd/system/django-gunicorn.service\n\n[Unit]\nDescription=gunicorn daemon\nAfter=network.target\n\n#--\n[Service]\nUser=foo\nGroup=www-data\nWorkingDirectory=/home/foo/django_test/repo\nExecStart=/Users/euiyoung.hwang/ES/Python_Workspace/python-django/.venv/bin/gunicorn \\\n        --workers 3 \\\n        --bind 0.0.0.0:9999 \\\n        config.wsgi:application\n\n[Install]\nWantedBy=multi-user.target\n#--\n\n# Run service\nsystemctl daemon-reload\n# Autostart when rebooting\nsudo systemctl enable django-gunicorn.service\nsystemctl start django-gunicorn\n\nsystemctl status django-gunicorn.service\n● django-gunicorn.service - \n```\n\nDocker Build \u0026 Run/Pytest : Docker build for running service \u0026 pytest through docker-compose.yml\n\n![Alt text](./screenshots/Django-Docker-Compose-Build.png)\n![Alt text](./screenshots/Django-Docker-Compose-Run.png)\n![Alt text](./screenshots/Django-Docker-Compose-Pytest.png)\n\nPytest (\u003ci\u003epoetry run pytest -v rest_api/tests\u003c/i\u003e)\n- [pytest] DJANGO_SETTINGS_MODULE = config.settings_dev for Dev Environment\n- poetry run pytest -v rest_api/tests --junitxml=test-reports/junit/pytest.xml --cov-report html --cov\n\n```bash\nplatform darwin -- Python 3.9.7, pytest-7.4.3, pluggy-1.3.0 -- /Users/euiyoung.hwang/ES/Python_Workspace/python-django/.venv/bin/python\ncachedir: .pytest_cache\ndjango: settings: config.settings_dev (from ini)\nrootdir: /Users/euiyoung.hwang/ES/Python_Workspace/python-django/rest_api/tests\nconfigfile: pytest.ini\nplugins: cov-4.1.0, django-4.5.2\ncollected 12 items                                                                                                                         \n\nrest_api/tests/test_build_query.py::test_build_skip SKIPPED (no way of currently testing this)                                       [  8%]\nrest_api/tests/test_build_query.py::test_build_terms[_term0] PASSED                                                                  [ 16%]\nrest_api/tests/test_build_query.py::test_build_terms_batch PASSED                                                                    [ 25%]\nrest_api/tests/test_elasticsearch.py::test_search_skip SKIPPED (no way of currently testing this)                                    [ 33%]\nrest_api/tests/test_elasticsearch.py::test_elasticsearch PASSED                                                                      [ 41%]\nrest_api/tests/test_elasticsearch.py::test_indics_analyzer_elasticsearch PASSED                                                      [ 50%]\nrest_api/tests/test_rest_api.py::test_api_skip SKIPPED (no way of currently testing this)                                            [ 58%]\nrest_api/tests/test_rest_api.py::test_api_test_swagger PASSED                                                                        [ 66%]\nrest_api/tests/test_rest_api.py::test_api_users_swagger[1] PASSED                                                                    [ 75%]\nrest_api/tests/test_rest_api.py::test_api_users_swagger[2] PASSED                                                                    [ 83%]\nrest_api/tests/test_rest_api.py::test_api_users_swagger[3] PASSED                                                                    [ 91%]\nrest_api/tests/test_rest_api.py::test_api_es_search_swagger PASSED                                                                   [100%]\n```\n\nHTTP Response status codes (\u003ci\u003ehttps://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204\u003c/i\u003e)\n```http\n100 Continue\n101 Switching Protocols\n102 Processing\n103 Early Hints\nExperimental\n200 OK\n201 Created\n202 Accepted\n203 Non-Authoritative Information\n204 No Content\n205 Reset Content\n206 Partial Content\n207 Multi-Status\n208 Already Reported\n226 IM Used\n300 Multiple Choices\n301 Moved Permanently\n302 Found\n303 See Other\n304 Not Modified\n307 Temporary Redirect\n308 Permanent Redirect\n400 Bad Request\n401 Unauthorized\n402 Payment Required\n403 Forbidden\n404 Not Found\n405 Method Not Allowed\n406 Not Acceptable\n407 Proxy Authentication Required\n408 Request Timeout\n409 Conflict\n410 Gone\n411 Length Required\n412 Precondition Failed\n413 Content Too Large\n414 URI Too Long\n415 Unsupported Media Type\n416 Range Not Satisfiable\n417 Expectation Failed\n418 I'm a teapot\n421 Misdirected Request\n422 Unprocessable Content\n423 Locked\n424 Failed Dependency\n425 Too Early\n426 Upgrade Required\n428 Precondition Required\n429 Too Many Requests\n431 Request Header Fields Too Large\n451 Unavailable For Legal Reasons\n500 Internal Server Error\n501 Not Implemented\n502 Bad Gateway\n503 Service Unavailable\n504 Gateway Timeout\n505 HTTP Version Not Supported\n506 Variant Also Negotiates\n507 Insufficient Storage\n508 Loop Detected\n510 Not Extended\n511 Network Authentication Required\n```\n\n\n#### Example for Crontab\n- All Linux distributions are equipped with the cron utility, which allows users to schedule jobs to run at certain fixed times.\n- The system-wide root cron jobs are located in the /etc/crontab file. The file contents can be displayed using any text editor, or utilities like cat and more. sudo is not required to display the system cron jobs.\n```bash\n# Example of job definition:\n# .---------------- minute (0 - 59)\n# |  .------------- hour (0 - 23)\n# |  |  .---------- day of month (1 - 31)\n# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...\n# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat\n# |  |  |  |  |\n# *  *  *  *  * user-name command to be executed\n17 *\t* * *\troot    cd / \u0026\u0026 run-parts --report /etc/cron.hourly\n25 6\t* * *\troot\ttest -x /usr/sbin/anacron || ( cd / \u0026\u0026 run-parts --report /etc/cron.daily )\n47 6\t* * 7\troot\ttest -x /usr/sbin/anacron || ( cd / \u0026\u0026 run-parts --report /etc/cron.weekly )\n52 6\t1 * *\troot\ttest -x /usr/sbin/anacron || ( cd / \u0026\u0026 run-parts --report /etc/cron.monthly )\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feuiyounghwang%2Fpython-django","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feuiyounghwang%2Fpython-django","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feuiyounghwang%2Fpython-django/lists"}