{"id":17143600,"url":"https://github.com/jitendra-ky/django-azure-deploy-manually","last_synced_at":"2026-02-15T12:37:27.007Z","repository":{"id":254489965,"uuid":"846669578","full_name":"jitendra-ky/django-azure-deploy-manually","owner":"jitendra-ky","description":"this is a documentary on how to deploy Django project on Azure manually with CI/CD pipeline. I make this a there is some error occur while I try to deploy my Django app from deployment center of Azure app service.","archived":false,"fork":false,"pushed_at":"2025-01-03T05:12:11.000Z","size":77,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-06T13:29:48.698Z","etag":null,"topics":["app-service","azure","deployment","django","manual"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jitendra-ky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2024-08-23T17:42:17.000Z","updated_at":"2025-01-03T05:27:41.000Z","dependencies_parsed_at":"2024-08-23T20:37:41.456Z","dependency_job_id":"67c75f78-1e20-4967-b8e4-c62e8f8c8dff","html_url":"https://github.com/jitendra-ky/django-azure-deploy-manually","commit_stats":null,"previous_names":["zsquare12/django-azure-deploy-manually","jitendra-ky/django-azure-deploy-manually"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jitendra-ky/django-azure-deploy-manually","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitendra-ky%2Fdjango-azure-deploy-manually","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitendra-ky%2Fdjango-azure-deploy-manually/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitendra-ky%2Fdjango-azure-deploy-manually/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitendra-ky%2Fdjango-azure-deploy-manually/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jitendra-ky","download_url":"https://codeload.github.com/jitendra-ky/django-azure-deploy-manually/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitendra-ky%2Fdjango-azure-deploy-manually/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29478355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-15T11:35:25.641Z","status":"ssl_error","status_checked_at":"2026-02-15T11:34:57.128Z","response_time":118,"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":["app-service","azure","deployment","django","manual"],"created_at":"2024-10-14T20:40:26.034Z","updated_at":"2026-02-15T12:37:26.979Z","avatar_url":"https://github.com/jitendra-ky.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"this page contain proper account of deploying A Django project on Azure web service manually without CI/CD pipeline.\n\n- Keep this private it contain secret environment variables;\n- we are assuming here that you create Django project with best practices\n    - You Django Project is a Repository of GitHub if not make it\n    - You install all the python packages required for your project in a virtual environment. If not do it.\n    - \n\n## Configure Django Project For Deployment\n\n---\n\n### Install additional packages for deployment\n\n- I am assuming here that you already create a virtual environment and install all the package which are required for your Django app to run on the same.\n- Install below packages on the same virtual environment\n\n```python\npip install psycopg2\npip install python-dotenv\npip install whitenoise\n\n```\n\n### write deployment settings\n\n- Create a [deployment.py](http://deployment.py/) file on the directory [settings.py](http://settings.py/) present\n- this file will treated as settings file in deployment environment\n- copy and page the below code on that. change if needed.\n\n```python\nimport os\nfrom .settings import *\nfrom .settings import BASE_DIR\n\nSECRET_KEY = os.environ['SECRET']\nALLOWED_HOSTS = [os.environ['WEBSITE_HOSTNAME']]\nCSRF_TRUSTED_ORIGINS = ['https://' + os.environ['WEBSITE_HOSTNAME']]\nDEBUG = False\n\n# WhiteNoise configuration\nMIDDLEWARE = [\n    'django.middleware.security.SecurityMiddleware',\n    'whitenoise.middleware.WhiteNoiseMiddleware',\n    'django.contrib.sessions.middleware.SessionMiddleware',\n    'django.middleware.common.CommonMiddleware',\n    'django.middleware.csrf.CsrfViewMiddleware',\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\n    'django.contrib.messages.middleware.MessageMiddleware',\n    'django.middleware.clickjacking.XFrameOptionsMiddleware',\n]\n\nSTATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'\nSTATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')\n\n'''\n# a way to add database connection\nconn_str = os.environ['AZURE_POSTGRESQL_CONNECTIONSTRING']\nconn_str_params = {pair.split('=')[0]: pair.split('=')[1] for pair in conn_str.split(' ')}\nDATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.postgresql',\n        'NAME': conn_str_params['dbname'],\n        'HOST': conn_str_params['host'],\n        'USER': conn_str_params['user'],\n        'PASSWORD': conn_str_params['password'],\n    }\n}\n'''\n\n```\n\n### tell our app when to use deployment settings\n\n- we need to change [wsgi.py](http://wsgi.py/) (present in same dir as [settings.py](http://settings.py/) in)\n- copy pate the below code on the, don’t forget to change the `project_name`\n\n```python\nimport os\nfrom django.core.wsgi import get_wsgi_application\n\nproject_name = \"my-project-name\"\n\nsettings_module = '.deployment' if 'WEBSITE_HOSTNAME' in os.environ else '.settings'\n\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', project_name+settings_module)\n\napplication = get_wsgi_application()\n\n```\n\n### create requirements.txt\n\n- caution: make sure virtual environment activate, and CMD is on the root directory of project (same on which [manage.py](http://manage.py/) present)\n- run the below command on CMD to create a requirements.txt\n\n```python\npip freeze \u003e requirements.txt\n\n```\n\n### Add a .production and .gitignore file\n\n- add a .production file in same directory as [manage.py](http://manage.py/) in with below code.\n\n```python\n[config]\nSCM_DO_BUILD_DURING_DEPLOYMENT=true\n\n```\n\n- add a .gitignore file in same dir as [manage.py](http://manage.py/) in with below code.\n\n```python\n# Byte-compiled / optimized / DLL files\n__pycache__/\n*.py[cod]\n*$py.class\n\n# Distribution / packaging\n.Python\nbuild/\ndevelop-eggs/\ndist/\ndownloads/\neggs/\n.eggs/\nlib/\nlib64/\nparts/\nsdist/\nvar/\nwheels/\npip-wheel-metadata/\nshare/python-wheels/\n*.egg-info/\n.installed.cfg\n*.egg\nMANIFEST\n\n# PyInstaller\n#  Usually these files are written by a python script from a template\n#  before PyInstaller builds the exe, so as to inject date/other infos into it.\n*.manifest\n*.spec\n\n# Installer logs\npip-log.txt\npip-delete-this-directory.txt\n\n# Unit test / coverage reports\nhtmlcov/\n.tox/\n.nox/\n.coverage\n.coverage.*\n.cache\nnosetests.xml\ncoverage.xml\n*.cover\n*.py,cover\n.hypothesis/\n.pytest_cache/\n\n# Django stuff:\n*.log\nlocal_settings.py\ndb.sqlite3\ndb.sqlite3-journal\n\n# PEP 582; used by e.g. github.com/David-OConnor/pyflow\n__pypackages__/\n\n# Environments\n.env\n.venv\nenv/\nvenv/\nENV/\nenv.bak/\nvenv.bak/\n\n```\n\n\u003caside\u003e\n💡 All done now your Django project is configured for Deployment, Commit and Push it to GitHub.\n\n\u003c/aside\u003e\n\n## Create and Configure Azure resources\n\n### Create a App service on Azure\n\n- with Python as a run-time environment. same version as you build your Django app on local machine\n\n### Set all necessary environment variables on azure service\n\nyou can use the JSON format for doing it faster\n\n```json\n[\n  {\n    \"name\": \"WEBSITE_HTTPLOGGING_RETENTION_DAYS\",\n    \"value\": \"1\",\n    \"slotSetting\": false\n  },\n  \n]\n\n```\n\n## Deploying Project Manually without CI/CD pipeline\n\n---\n\n### Make app service Authentication for GitHub with SSH key\n\n1. Generate SSH-key with Azure App Service SSH\n    \n    ```bash\n    ssh-keygen -t rsa -b 4096 -C \"jk69854@gmail.com\"\n    \n    ```\n    \n    ```bash\n    cat ~/.ssh/id-rsa.pub\n    \n    ```\n    \n2. Set this SSH-key in GitHub with GUI\n    \n    \u003caside\u003e\n    💡 ‣ | https://github.com/settings/keys\n    \n    \u003c/aside\u003e\n    \n    above is the direct link for that same site, better to save with the name of App-service\n    \n3. Verify Connection\n    \n    ```bash\n    ssh -T git@github.com\n    \n    ```\n    \n\n### Clone the Project Repo and Build it\n\n1. Install git in App service\n    \n    ```bash\n    apt install git\n    \n    ```\n    \n2. clone the repo\n    \n    ```bash\n    cd ~/home/site/wwwroot/ # more to deployment directory\n    git clone \u003cssh-url-of-repo\u003e # remember ssh url and http url\n    \n    ```\n    \n3. Build it\n    \n    here the the build command either you can do it by yourself or just copy past below instruction in chat-gpt by putting your `repo-name` and `github-username` on top line and GPT will do give a handy command file for you that you can copy past directly on app-service SSH\n    \n    ```bash\n    # my repo name is [pur-repo-name-here] my github username is [github-username]\n    # re write all these command for me so that I can copy page these in my azure app service cli directly\n    cd ~/home/site/wwwroot/ # more to deployment directory\n    cd \u003crepo-name\u003e # move into the project\n    git checkout \u003cbranch-name\u003e # switch to branch you want to deploy\n    cd .. # go back\n    python -m venv antenv # create python virtual environment with name antenv\n    source antenv/bin/activate # activate the virtual environment\n    pip install -r \u003crepo-name\u003e/requirements.txt # install the requirement of your django project\n    pip install gunicorn # might be gunicorn not in the requirements\n    cd \u003crepo-name\u003e # again to into the repo directory\n    py manage.py migrate # migrate the migrations\n    py manage.py collectstatic --noinput # collect all the static files\n    \n    ```\n    \n\n### Test if things done correctly or not\n\n1. Open two window of app-service SSH and navigate to repo directory on both.\n    \n    ```bash\n    cd ~/home/site/wwwroot/my-repo/ # same file where manage.py is present\n    \n    ```\n    \n2. test server is running properly with | python [manage.py](http://manage.py/) runserver\n    \n    ```bash\n    # on SSH window 1\n    py manage.py runserver 1010 # run the runsever on port 1010 as might be 8000 already busy\n    # TIP: you can also see in this ouput which setting is working s dettings.py or deployment.py\n    \n    # on SSH window 2 while server is continuously running on window 1\n    curl \u003chttp://localhost:1010/\u003e # lisen to the loclhost port 1010\n    # if it give no output --\u003e good test passed\n    # if it give some html context which show erro code 400 --\u003e test failed something is wrong\n    # if it give some html context which do not contain error --\u003e text passed\n    \n    # now u can stop the server at window 1 by crt+C\n    \n    ```\n    \n3. test by running `gunicorn` server\n    \n    ```bash\n    # on SSH window 1\n    gunicorn --bind 0.0.0.0:1010 sharktodo2.wsgi:application --access-logfile - --error-logfile - # run the runsever on port 1010 as might be 8000 already busy\n    \n    # on SSH window 2 while server is continuously running on window 1\n    curl \u003chttp://localhost:1010/\u003e # lisen to the loclhost port 1010\n    # if it give no output --\u003e good test passed\n    # if it give some html context which show erro code 400 --\u003e test failed something is wrong\n    # if it give some html context which do not contain error --\u003e text passed\n    \n    # now u can stop the server at window 1 by crt+C\n    \n    ```\n    \n\n### Tell app-service to run your Django app on hosting port (8000) not default one.\n\nnavigate to app service configuration and set give start-up command there and save it.\n\njust wait for max 5 min and visit your app service URL your Django app will be live there\n\n\u003cimg src=\"azure_startup_command.png\" /\u003e\n\n```bash\nsource antenv/bing/activate\ncd [your-repo-name]\ngunicorn --bind 0.0.0.0:8000 sharktodo2.wsgi:application --access-logfile - --error-logfile -\n\n```\n\n### Some Debugging Tips\n\n1. you can check Log of of from the app-service sidebar Log Stream\n    1. and even you can turn more detailed log from app-service side-bar app-service-logs\n2. have doubt my [deployment.py](http://deployment.py/) settings are running or not\n    1. just run python [manage.py](http://manage.py/) runserver from the ssh it will show which setting are running","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjitendra-ky%2Fdjango-azure-deploy-manually","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjitendra-ky%2Fdjango-azure-deploy-manually","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjitendra-ky%2Fdjango-azure-deploy-manually/lists"}