{"id":26701679,"url":"https://github.com/tarequzzaman/django-learning","last_synced_at":"2026-04-24T12:32:03.597Z","repository":{"id":38992754,"uuid":"263829896","full_name":"Tarequzzaman/Django-Learning","owner":"Tarequzzaman","description":"it cover basic to advance ","archived":false,"fork":false,"pushed_at":"2023-05-25T17:55:56.000Z","size":62,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-12T03:14:20.576Z","etag":null,"topics":["celery","celery-task","distributed-tasks","django","multiple-db","orm","rabbitmq","rest-api","rest-framework"],"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/Tarequzzaman.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":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-05-14T06:06:20.000Z","updated_at":"2021-10-29T08:06:09.000Z","dependencies_parsed_at":"2025-06-12T03:10:22.622Z","dependency_job_id":"5c317bc1-a9eb-40ff-959b-d9541329193c","html_url":"https://github.com/Tarequzzaman/Django-Learning","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Tarequzzaman/Django-Learning","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tarequzzaman%2FDjango-Learning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tarequzzaman%2FDjango-Learning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tarequzzaman%2FDjango-Learning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tarequzzaman%2FDjango-Learning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tarequzzaman","download_url":"https://codeload.github.com/Tarequzzaman/Django-Learning/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tarequzzaman%2FDjango-Learning/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32223879,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T10:26:35.452Z","status":"ssl_error","status_checked_at":"2026-04-24T10:25:27.643Z","response_time":64,"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":["celery","celery-task","distributed-tasks","django","multiple-db","orm","rabbitmq","rest-api","rest-framework"],"created_at":"2025-03-27T01:29:49.000Z","updated_at":"2026-04-24T12:32:03.582Z","avatar_url":"https://github.com/Tarequzzaman.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003chtml\u003e\n\n\u003cbody\u003e\n\u003ch2\u003eInstallation Process: \u003c/h2\u003e\n\n1.  Need to install mysql client the [docs](https://pypi.org/project/mysqlclient/) is here \n2. Need MongoDB install \n3. Install rabbitmq server \n\n    ```\n    apt-get install rabbitmq-server\n    running: \n    rabbitmq-server\n    ```\n    MacOS\n    ```\n    brew install rabbitmq\n    export PATH=$PATH:/usr/local/sbin\n     \n    running: \n    rabbitmq-server\n    or \n    brew service start rabbitmq\n    ```\n\n   \n4. install requirements from the requirements.txt file \n    ```\n    pip install -r requirements.txt\n    ```\n     \n   \n      \n---\n\n\u003ch2\u003eMultipleDB\u003c/h2\u003e\n\n1. Deault \u003cbr\u003e\nIn my project I am adding `mysql` as `default` DB. Where db_name is `testing`. You dont need to `DATABASE_ROUTERS` for `default` DB\n\n    ``` python\n     'default': {\n        'ENGINE': 'django.db.backends.mysql',\n        'NAME': 'testing',\n        'USER': 'root',\n        'PASSWORD': 'root',\n        'HOST': '127.0.0.1',   # Or an IP Address that your DB is hosted on\n        'PORT': 3306,\n        'OPTIONS': {\n            'charset': 'utf8mb4',\n        },\n        'TEST': {\n            'CHARSET': 'utf8mb4',\n            'COLLATION': 'utf8mb4_unicode_ci',\n        }\n    }, \n   ```\n\n\n2. another \u003cbr\u003e\n\n3. MongoDB\u003cbr\u003e\n   The source is found  \u003ca href=\"https://bezkoder.com/django-mongodb-crud-rest-framework/\"\u003ehere\u003c/a\u003e\n   Steps: \u003cbr\u003e\n\n   - For mongodb we have to create an app **mongoDBWork**\u003cbr\u003e\n\n   - install djongo for MongoDB engine \u003cbr\u003e\n\n        ```\n           pip install djongo\n        ```\n  \n\n   - Add Db engine on setting.py\u003cbr\u003e\n\n        ```python\n             DATABASES = {\n                .\n                .\n\n                'mongo':{  \n                    'ENGINE':   'djongo',\n                    'NAME':     'local', # name of the database \n                    'CLIENT': {\n                        'host': '127.0.0.1',\n                        'port': 27017,\n                        'username': 'user_name',\n                        'password': 'password',\n                        'authSource': 'auth db name'\n                     }\n                }\n             }\n        ```\n    - Since it is not default Database we Have to add DATABASE_ROUTERS for this DB to your `setting.py` file\u003cbr\u003e\n\n        ```python \n           DATABASE_ROUTERS = ['otherdbapp.router.OtherAppDB',\"mongoDBwork.router.MongoDBRouter\"]\n        ```\n        Description of DATABASE_ROUTERS:\u003cbr\u003e\n        - mongoDBwork : App Name\u003cbr\u003e\n        - router : router.py file inser\u003cbr\u003e\n        - MongoDBRouter: class name on the `router.py` file \u003cbr\u003e\n        - Please have a look on `router.py` file \u003cbr\u003e\n\n\n    - Create a model name Posts \u003cbr\u003e\n\n    - migration \u003cbr\u003e\n        ```\n      python manage.py makemigrations mongoDBwork\n        ```\n    - Migrate DB\u003cbr\u003e\n        ```shell\n        python manage.py migrate --database=mongo  \n        ```\n\n\nThe database section contain 3 DB connected. Basically the second DB is also `Mysql`. Going forward I added `postgresql` as Second DB\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n\n\u003ch2\u003eTestcase: \u003c/h2\u003e\n\n\n---\n\u003cp\u003eUnittest is very importent for CI/CD. Whenever you wirte a code you need to initaiate test case for this code\u003c/p\u003e\n\u003cbr\u003e\n\n\u003cp\u003eBelow I have added some code for testing the views functions( get apis)\u003c/p\u003e\n\n\n1. urls.py for otherdbapp\n\n```python\n\n\turlpatterns = [\n          #url(r'^admin/', admin.site.urls),\n   \t  url(r'create_user', create_user),\n  \t  url(r'get_user/', get_user),\n\t]\n```\n\u003cbr\u003e\nfrom the urls.py we can see there is two basic(not REST) apis path(create_user, get_user). Now we can move the views function these path\n\n\u003cbr\u003e\n2.  The view function for these two url path are given here \u003cstrong\u003eviews.py\u003c/strong\u003e\n\n\n```python\ndef create_user(requests):\n    try:\n        first_name = requests.GET.get(\"first_name\")\n        last_name = requests.GET.get(\"last_name\")\n        phone =  requests.GET.get('phone')\n        email = requests.GET.get('email')\n        data = Users.objects.create(first_name= first_name, last_name= last_name, phone = phone, email = email)\n        uuid = data.id\n        return Response_data.success_response([{'id': uuid}])\n    except Exception as E:\n        return Response_data.failure_response(\"Something Went Wrong\", str(E))\n\n\n\ndef get_user(requests):\n    return Response_data.failure_response(\"Something Went Wrong\", \"\")\t\n\n```\n\n3. Now we can write testcase for these two functions   \u003cstrong\u003etest.py\u003c/strong\u003e\u003cbr\u003e\n\n\n```python\nclass TestView(unittest.TestCase):\n    def test_create_users(self):\n        client = Client()\n        response= client.get(reverse(create_user), {'first_name': 'john', 'last_name': 'smith', 'phone': \"......\", 'email': \"/.........\"})\n        self.assertEqual(response.status_code, 200)\n\n    def test_get_user(self):\n        client = Client()\n        response= client.get(reverse(get_user))\n        self.assertEqual(response.status_code, 450)\n```\n\n\u003ch2\u003eTokenAuthentication: \u003c/h2\u003e \n\n---\n\nI am trying to apply TokenAuthentication  on My an api  `http://127.0.0.1:8000/data/get_all_data/`.  The process is given here step by step:\n\n1.  Install django rest framework\n```\n    pip install djangorestframework\n\n```\n\n2. Adding **rest_framework**  **'rest_framework.authtoken'** on my `INSTALLED_APPS`  py and `DEFAULT_AUTHENTICATION_CLASSES` inside the testDjango/settings.py\n\n```\nINSTALLED_APPS = [\n   .\n   .\n   .\n    \n    'rest_framework',\n    'rest_framework.authtoken',  # \u003c-- Here\n\n\n    .\n    .\n    .\n]\n```\n\n\n```\nREST_FRAMEWORK = {\n    'DEFAULT_AUTHENTICATION_CLASSES': [\n        'rest_framework.authentication.TokenAuthentication',  # \u003c-- And here\n    ],\n}\n```\n\n3. Then Run this command \n\n```\npython manage.py migrate\npython manage.py createsuperuser --username Tareq --email tareqcse12@gmail.com\n\n```\n\n\n\n4. For getting the user (Tareq) token we need to add some code on testDjango/urls.py \n\n\n\n\n```python\n\nfrom django.urls import path\nfrom rest_framework.authtoken.views import obtain_auth_token  # \u003c-- Here\n\n\nurlpatterns = [\n  #url(r'^admin/', admin.site.urls),\n     .\n     .\n     .\n     path('api-token-auth/', obtain_auth_token, name='api_token_auth')\n]\n```\n\n5. Call the api with username and password for getting token\n\n\n\u003cdiv style=\"text-align:center\"\u003e\n\u003cimg src=\"https://i.imgur.com/uaubFEO.png\" width=\"500\" height=\"300\"\u003e\n\u003c/div\u003e\n\n\n6. The token is generated now I want to authenticate my api using this credential.  Now I am moving My app historical_data/views.py. I import the necessary libraries for this authentcation\n\n\n```python\nfrom rest_framework.permissions import IsAuthenticated \nfrom rest_framework.decorators import api_view, permission_classes\n\n```\n```python \n@api_view([\"GET\"])\n@permission_classes([IsAuthenticated])\ndef get_all_data(requests):\n    try:\n        event_data = PriceHistory.objects.filter()\n        serializer = PriceHistorySerializer(event_data, many=True)\n        return Response_data.success_response(serializer.data)\n    except Exception as E:\n        return Response_data.failure_response(\"Something Went Wrong\", str(E))\n\n```\n\n\n7. The Authentication is added now I want to test it with Token and Without Token \n\n**With token request:**\n\n\u003cdiv style=\"text-align:center\"\u003e\n\u003cimg src=\"https://i.imgur.com/5GlTYH3.png\" width=\"500\" height=\"300\"\u003e\n\u003c/div\u003e\n\n**Without token request:**\n\n\u003cdiv style=\"text-align:center\"\u003e\n\u003cimg src=\"https://i.imgur.com/jxlTxGB.png\" width=\"500\" height=\"300\"\u003e\n\u003c/div\u003e\n\nThe source for TokenAuthentication is found \u003ca href=\"https://simpleisbetterthancomplex.com/tutorial/2018/11/22/how-to-implement-token-authentication-using-django-rest-framework.html\"\u003ehere\u003c/a\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarequzzaman%2Fdjango-learning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftarequzzaman%2Fdjango-learning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarequzzaman%2Fdjango-learning/lists"}