{"id":20619667,"url":"https://github.com/twtrubiks/vscode_django_note","last_synced_at":"2025-04-15T11:55:03.251Z","repository":{"id":49402865,"uuid":"192077527","full_name":"twtrubiks/vscode_django_note","owner":"twtrubiks","description":"如何使用 VScode 執行 Django 📝","archived":false,"fork":false,"pushed_at":"2024-09-08T07:29:18.000Z","size":16,"stargazers_count":20,"open_issues_count":1,"forks_count":4,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-28T19:53:42.735Z","etag":null,"topics":["django","tutorial","vscode"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twtrubiks.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":"2019-06-15T12:44:32.000Z","updated_at":"2024-09-24T14:19:45.000Z","dependencies_parsed_at":"2024-09-08T08:34:56.627Z","dependency_job_id":"01bc01de-ce68-4cc4-878e-90b56dd5b392","html_url":"https://github.com/twtrubiks/vscode_django_note","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2Fvscode_django_note","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2Fvscode_django_note/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2Fvscode_django_note/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2Fvscode_django_note/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twtrubiks","download_url":"https://codeload.github.com/twtrubiks/vscode_django_note/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249067775,"owners_count":21207395,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["django","tutorial","vscode"],"created_at":"2024-11-16T12:12:14.607Z","updated_at":"2025-04-15T11:55:03.232Z","avatar_url":"https://github.com/twtrubiks.png","language":"Python","readme":"# vscode-django-note\n\n 如何使用 VScode 執行 Django 📝\n\n* [Youtube Tutorial PART 1 - 如何使用 VScode 執行 Django - 基本篇](https://youtu.be/uhxl_YFc-wc)\n\n* [Youtube Tutorial PART 2 - 如何使用 VScode 執行 Django Testing 以及 pylint_django](https://youtu.be/t-3FqO96hbQ)\n\n## 教學\n\n### 安裝環境\n\n建議大家先閱讀以下這篇文章 ( 假如你沒用 VScode 寫過 Python )，\n\n[Visual Studio Code Python 基本設定篇](https://youtu.be/tS4beaq9ies)\n\n安裝 [requirements.txt](requirements.txt)\n\n\u003e pip install -r requirements.txt\n\n安裝 VScode Python 套件\n\n![alt tag](https://i.imgur.com/5lZFm5f.png)\n\n### 設定 Django Debug\n\n選取 `Debug \u003e Add Configuration`，會跳出 [launch.json](https://github.com/twtrubiks/vscode_django_note/blob/master/.vscode/launch.json)，\n\n![alt tag](https://i.imgur.com/42G2mFL.png)\n\n這邊是預設的設定，其他更詳細的設定可參考 [tutorial-django](https://code.visualstudio.com/docs/python/tutorial-django)\n\n`justMyCode` 這個主要為可以中斷點到外部 library (第三方) 裡面的東西.\n\n### 執行 Django Debug\n\n選取 `Debug \u003e Start Debugging` 或是 F5 開始 Debug\n\n![alt tag](https://i.imgur.com/o75KTkt.png)\n\n成功執行\n\n![alt tag](https://i.imgur.com/zdkvmfS.png)\n\n### Vscode 設定中斷點\n\n中斷點也很簡單，在需要中斷的地方點一下，會有一個紅色的點。\n\n![alt tag](https://i.imgur.com/1QDe6bM.png)\n\n左邊可以看目前的變數，下方的 DEBUG CONSOLE 也很好用，\n\n可以在這邊輸入你想執行的程式。\n\n### 設定 Django Shell 中斷點\n\n有時候需要使用 Django Shell 或是 [Django management commands](https://github.com/twtrubiks/django-tutorial/tree/django4_custom_management_commands),\n\n這時候可以這樣設定, [.vscode/launch.json](https://github.com/twtrubiks/vscode_django_note/blob/master/.vscode/launch.json)\n\n```json\n{\n    \"name\": \"Python:Django Shell\",\n    \"type\": \"debugpy\",\n    \"request\": \"launch\",\n    \"program\": \"${workspaceFolder}/manage.py\",\n    \"args\": [\n        // \"welcome\",  // command\n    ],\n    \"django\": true,\n    \"justMyCode\": false,\n},\n```\n\n如果你有 management commands, 就在 args 裡面設定即可.\n\n### 設定 Django Testing\n\n在 Django 中執行 Testing 的指令為\n\n\u003e python manage.py test\n\n如果我只想單純對某個資料夾 ( 例如 musics ) 底下跑 testing\n\n\u003e python manage.py test musics/\n\n更多詳細可參考\n\n[Writing and running tests](https://docs.djangoproject.com/en/2.2/topics/testing/overview/)\n\n這邊有一個簡單的 [musics/test.py](https://github.com/twtrubiks/vscode_django_note/blob/master/musics/tests.py)，\n\n該如何設定讓他執行呢 ?\n\n當然，可以直接在命令列下指令，可是我希望整合 VSCode，\n\n回到剛剛前面介紹的 [launch.json](https://github.com/twtrubiks/vscode_django_note/blob/master/.vscode/launch.json)，\n\n在這邊只需要再加一個即可 args 的部分改成 test，\n\n就相當於是執行，\n\n\u003e python manage.py test\n\n![alt tag](https://i.imgur.com/MCbvVJ9.png)\n\n儲存後，如果你點選下方，你會發現你多了一個選項 ( Django Test )\n\n![alt tag](https://i.imgur.com/1mXqm4b.png)\n\n選擇 Django Test 就會開始跑 Testing 了\n\n![alt tag](https://i.imgur.com/msP7Uzm.png)\n\n### 設定 pylint_django\n\n之前再 [Visual Studio Code Python 基本設定篇](https://youtu.be/tS4beaq9ies) 這篇有教大家\n\n`pip install pylint`，但這邊卻是要 `pip install pylint_django`，原因是因為如果\n\n只安裝 pylint，自己定義的 ORM 很多會出現在 PROBLEMS 裡面，\n\n![alt tag](https://i.imgur.com/9Sp7g4Z.png)\n\n所以要安裝 pylint_django 修正他，安裝完之後須再 [settings.json](https://github.com/twtrubiks/vscode_django_note/blob/master/.vscode/settings.json) 加上\n\n```json\n\"python.linting.pylintArgs\": [\n        \"--load-plugins=pylint_django\",\n    ]\n```\n\n儲存之後，你就會發現被修正了 ( 剛剛的錯誤消失了 )，\n\n然後底下會有一些 pylint 的建議。\n\n![alt tag](https://i.imgur.com/uHaLSBH.png)\n\n更多 pylint_django 說明可參考 [pylint_django](https://github.com/PyCQA/pylint-django)。\n\n## 執行環境\n\n* Python 3.6.6\n\n## Donation\n\n文章都是我自己研究內化後原創，如果有幫助到您，也想鼓勵我的話，歡迎請我喝一杯咖啡:laughing:\n\n[Thank-you-for-donate](https://github.com/twtrubiks/Thank-you-for-donate)\n\n## License\n\nMIT license\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwtrubiks%2Fvscode_django_note","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwtrubiks%2Fvscode_django_note","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwtrubiks%2Fvscode_django_note/lists"}