├── .gitignore ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── remote-debugging-docker-django ├── .vscode │ └── launch.json ├── README.md ├── dockerfile ├── home │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── migrations │ │ └── __init__.py │ ├── models.py │ ├── templates │ │ └── index.html │ ├── tests.py │ ├── urls.py │ └── views.py ├── manage.py ├── mysite │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── requirements.txt ├── remote-debugging-docker ├── .gitignore ├── .vscode │ └── launch.json ├── README.md ├── dockerfile └── sample.py ├── remote-debugging-flask ├── .vscode │ ├── launch.json │ └── settings.json ├── README.md └── app.py ├── remote-debugging-locally ├── .gitignore ├── .vscode │ └── launch.json ├── README.md └── sample.py ├── remote-debugging ├── .gitignore ├── .vscode │ └── launch.json ├── README.md └── sample.py ├── sample-django ├── .vscode │ ├── launch.json │ └── settings.json ├── README.md ├── home │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── migrations │ │ └── __init__.py │ ├── models.py │ ├── templates │ │ └── index.html │ ├── tests.py │ ├── urls.py │ └── views.py ├── manage.py ├── mysite │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── requirements.txt ├── sample-flask ├── .vscode │ ├── launch.json │ └── settings.json ├── README.md └── app.py └── samples.code-workspace /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.exclude": { 3 | "**/.git": true, 4 | "**/.svn": true, 5 | "**/.hg": true, 6 | "**/CVS": true, 7 | "**/.DS_Store": true, 8 | "**/__pycache__/**": true, 9 | "**/.pyc": true 10 | }, 11 | "search.exclude": { 12 | "**/node_modules": true, 13 | "**/bower_components": true, 14 | "**/.env/**": true 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Don Jayamanne 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vscode-python-samples 2 | Samples for VS Code Python extension 3 | -------------------------------------------------------------------------------- /remote-debugging-docker-django/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Python: Attach", 9 | "type": "python", 10 | "request": "attach", 11 | "localRoot": "${workspaceFolder}", 12 | "remoteRoot": "src/", 13 | "port": 3000, 14 | "secret": "my_secret", 15 | "host": "localhost" 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /remote-debugging-docker-django/README.md: -------------------------------------------------------------------------------- 1 | # Django Debugging Sample 2 | 3 | **Note:** 4 | This sample uses Python 3.6 and Django 2.0 5 | This is a sample Django application created using [tutorial](https://docs.djangoproject.com/en/2.0/intro/tutorial01/) on the Django website 6 | 7 | ## Setup your remote environment 8 | ### Step 1: Build docker image and run it 9 | * Open a temrinal window 10 | * Type the following command in the terminal window 11 | `docker build -t remote-debugging-docker-django .` 12 | * Type the following command in the terminal window 13 | `docker run -it -p 3000:3000 -p 8000:8000 remote-debugging-docker-django` 14 | * Wait for Django to start in the container 15 | * Once started you should see something similar to the following in the terminal window: 16 | ```shell 17 | Starting development server at http://127.0.0.1:8000/ 18 | Quit the server with CONTROL-C. 19 | ``` 20 | 21 | ### Step 2: Confirm Django is running 22 | * Open a browser window pointing to the Url that Django is listening on 23 | * Confirm Django home page appears 24 | * Next navigate to the `polls` page ([http://127.0.0.1:8000/polls](http://127.0.0.1:8000/polls)) 25 | * Confirm the output on the browser window is `Hello, world. You're at the polls index.` 26 | 27 | ## Setup your local environment 28 | ### Step 1: Open the workspace in your local environment 29 | * This step will ensure you have setup the program to be debugged locally. 30 | * You do not to setup the Python environment locally to debug a remote environment. 31 | 32 | ### Step 2: Attach the debugger 33 | * Go into the debugger menu and select `Python: Attach` and press the green arrow icon 34 | 35 | ### Step 3: Debug Django 36 | * Open the `polls/views.py` file and add a break point to the line `return HttpResponse("Hello, world. You're at the polls index.")` 37 | * Refresh your browser window. 38 | * The debugger should hit the breakpoint. 39 | -------------------------------------------------------------------------------- /remote-debugging-docker-django/dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.6-alpine 2 | COPY . src/ 3 | RUN pip install --no-cache django ptvsd==3.0.0 4 | EXPOSE 3000 8000 5 | CMD ["python", "src/manage.py", "runserver", "--noreload", "--nothreading", "0.0.0.0:8000"] 6 | -------------------------------------------------------------------------------- /remote-debugging-docker-django/home/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DonJayamanne/vscode-python-samples/8b78d3048333f5f67484ed9d0716892633cda574/remote-debugging-docker-django/home/__init__.py -------------------------------------------------------------------------------- /remote-debugging-docker-django/home/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /remote-debugging-docker-django/home/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class HomeConfig(AppConfig): 5 | name = 'home' 6 | -------------------------------------------------------------------------------- /remote-debugging-docker-django/home/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DonJayamanne/vscode-python-samples/8b78d3048333f5f67484ed9d0716892633cda574/remote-debugging-docker-django/home/migrations/__init__.py -------------------------------------------------------------------------------- /remote-debugging-docker-django/home/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /remote-debugging-docker-django/home/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | My Home Page 5 | 6 | 7 |

Sample Django Application

8 |

{{ value_from_server }}

9 |

{{ another_value_from_server }}

10 | 11 | 12 | -------------------------------------------------------------------------------- /remote-debugging-docker-django/home/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /remote-debugging-docker-django/home/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | 3 | from . import views 4 | 5 | urlpatterns = [ 6 | path('', views.index, name='index'), 7 | ] 8 | -------------------------------------------------------------------------------- /remote-debugging-docker-django/home/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from django.template import loader 3 | 4 | 5 | def index(request): 6 | context = { 7 | 'value_from_server':'one', 8 | 'another_value_from_server':'two' 9 | } 10 | return render(request, 'index.html', context) 11 | -------------------------------------------------------------------------------- /remote-debugging-docker-django/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | import ptvsd 5 | 6 | address = ('0.0.0.0', 3000) 7 | ptvsd.enable_attach('my_secret', address) 8 | 9 | if __name__ == "__main__": 10 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") 11 | try: 12 | from django.core.management import execute_from_command_line 13 | except ImportError: 14 | # The above import may fail for some other reason. Ensure that the 15 | # issue is really that Django is missing to avoid masking other 16 | # exceptions on Python 2. 17 | try: 18 | import django 19 | except ImportError: 20 | raise ImportError( 21 | "Couldn't import Django. Are you sure it's installed and " 22 | "available on your PYTHONPATH environment variable? Did you " 23 | "forget to activate a virtual environment?" 24 | ) 25 | raise 26 | execute_from_command_line(sys.argv) 27 | -------------------------------------------------------------------------------- /remote-debugging-docker-django/mysite/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DonJayamanne/vscode-python-samples/8b78d3048333f5f67484ed9d0716892633cda574/remote-debugging-docker-django/mysite/__init__.py -------------------------------------------------------------------------------- /remote-debugging-docker-django/mysite/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for mysite project. 3 | 4 | Generated by 'django-admin startproject' using Django 1.11.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.11/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/1.11/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = '5u06*)07dvd+=kn)zqp8#b0^qt@*$8=nnjc&&0lzfc28(wns&l' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | ] 41 | 42 | MIDDLEWARE = [ 43 | 'django.middleware.security.SecurityMiddleware', 44 | 'django.contrib.sessions.middleware.SessionMiddleware', 45 | 'django.middleware.common.CommonMiddleware', 46 | 'django.middleware.csrf.CsrfViewMiddleware', 47 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 48 | 'django.contrib.messages.middleware.MessageMiddleware', 49 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 50 | ] 51 | 52 | ROOT_URLCONF = 'mysite.urls' 53 | 54 | TEMPLATES = [ 55 | { 56 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 57 | 'DIRS': ['src/home/templates'], 58 | 'APP_DIRS': True, 59 | 'OPTIONS': { 60 | 'context_processors': [ 61 | 'django.template.context_processors.debug', 62 | 'django.template.context_processors.request', 63 | 'django.contrib.auth.context_processors.auth', 64 | 'django.contrib.messages.context_processors.messages', 65 | ], 66 | }, 67 | }, 68 | ] 69 | 70 | WSGI_APPLICATION = 'mysite.wsgi.application' 71 | 72 | 73 | # Database 74 | # https://docs.djangoproject.com/en/1.11/ref/settings/#databases 75 | 76 | DATABASES = { 77 | 'default': { 78 | 'ENGINE': 'django.db.backends.sqlite3', 79 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 80 | } 81 | } 82 | 83 | 84 | # Password validation 85 | # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators 86 | 87 | AUTH_PASSWORD_VALIDATORS = [ 88 | { 89 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 90 | }, 91 | { 92 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 93 | }, 94 | { 95 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 96 | }, 97 | { 98 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 99 | }, 100 | ] 101 | 102 | 103 | # Internationalization 104 | # https://docs.djangoproject.com/en/1.11/topics/i18n/ 105 | 106 | LANGUAGE_CODE = 'en-us' 107 | 108 | TIME_ZONE = 'UTC' 109 | 110 | USE_I18N = True 111 | 112 | USE_L10N = True 113 | 114 | USE_TZ = True 115 | 116 | 117 | # Static files (CSS, JavaScript, Images) 118 | # https://docs.djangoproject.com/en/1.11/howto/static-files/ 119 | 120 | STATIC_URL = '/static/' 121 | -------------------------------------------------------------------------------- /remote-debugging-docker-django/mysite/urls.py: -------------------------------------------------------------------------------- 1 | """mysite URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/1.11/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.conf.urls import url, include 14 | 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 15 | """ 16 | from django.conf.urls import url, include 17 | from django.contrib import admin 18 | from django.views.generic import RedirectView 19 | 20 | urlpatterns = [ 21 | url(r'^home/', include('home.urls')), 22 | url(r'^admin/', admin.site.urls), 23 | url('', RedirectView.as_view(url='/home/')), 24 | ] 25 | -------------------------------------------------------------------------------- /remote-debugging-docker-django/mysite/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for mysite project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /remote-debugging-docker-django/requirements.txt: -------------------------------------------------------------------------------- 1 | Django==2.0.2 2 | ptvsd==3.0.0 3 | -------------------------------------------------------------------------------- /remote-debugging-docker/.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/settings.json 2 | -------------------------------------------------------------------------------- /remote-debugging-docker/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Attach (Remote Debug)", 9 | "type": "python", 10 | "request": "attach", 11 | "port": 3000, 12 | "host": "localhost", 13 | "pathMappings": [ 14 | {"localRoot": "${workspaceFolder}", "remoteRoot": "/src/"} 15 | ], 16 | "redirectOutput": false 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /remote-debugging-docker/README.md: -------------------------------------------------------------------------------- 1 | # Remote Debugging Sample (on the same Machine) 2 | 3 | ## Setup your remote environment 4 | ### Step 1: Build docker image and run it 5 | * Open a temrinal window 6 | * Type the following command in the terminal window 7 | `docker build -t remote-debugging-docker .` 8 | * Type the following command in the terminal window 9 | `docker run -it -p 3000:3000 remote-debugging-docker` 10 | * Confirm the following is displayed in the terminal window 11 | `Waiting to attach` 12 | 13 | ## Setup your local environment 14 | ### Step 1: Open the workspace in your local environment 15 | * This step will ensure you have setup the program to be debugged locally. 16 | * You do not to setup the Python environment locally to debug a remote environment. 17 | 18 | ### Step 2: Attach the debugger 19 | * Open `sample.py` 20 | * Add a breakpoint to the line `print("attached")` 21 | * Go into the debugger menu and select `Python: Attach` and press the green arrow icon 22 | * Wait for around 2 seconds and the debugger should hit at the breakpoint 23 | -------------------------------------------------------------------------------- /remote-debugging-docker/dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.6-alpine 2 | COPY . src/ 3 | RUN pip install --no-cache ptvsd 4 | EXPOSE 3000 5 | CMD ["python", "src/sample.py"] 6 | -------------------------------------------------------------------------------- /remote-debugging-docker/sample.py: -------------------------------------------------------------------------------- 1 | import ptvsd 2 | import time 3 | import os 4 | 5 | print("Waiting to attach") 6 | 7 | address = ('0.0.0.0', 3000) 8 | ptvsd.enable_attach(address) 9 | ptvsd.wait_for_attach() 10 | 11 | time.sleep(2) 12 | 13 | print("attached") 14 | print("end") 15 | -------------------------------------------------------------------------------- /remote-debugging-flask/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Python: Attach", 9 | "type": "python", 10 | "request": "attach", 11 | "localRoot": "${workspaceFolder}", 12 | "remoteRoot": "${workspaceFolder}", 13 | "port": 3000, 14 | "secret": "my_secret", 15 | "host": "localhost" 16 | }, 17 | { 18 | "name": "Python: Flask", 19 | "type": "python", 20 | "request": "launch", 21 | "stopOnEntry": false, 22 | "pythonPath": "${config:python.pythonPath}", 23 | "module": "flask", 24 | "cwd": "${workspaceFolder}", 25 | "env": { 26 | "FLASK_APP": "${workspaceFolder}/app.py" 27 | }, 28 | "args": [ 29 | "run", 30 | "--no-debugger", 31 | "--no-reload" 32 | ], 33 | "envFile": "${workspaceFolder}/.env", 34 | "debugOptions": [ 35 | "RedirectOutput" 36 | ], 37 | "console": "integratedTerminal", 38 | "internalConsoleOptions": "neverOpen" 39 | } 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /remote-debugging-flask/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.exclude": { 3 | "**/.git": true, 4 | "**/.svn": true, 5 | "**/.hg": true, 6 | "**/CVS": true, 7 | "**/.DS_Store": true, 8 | "**/__pycache__/**": true, 9 | "**/.pyc": true 10 | }, 11 | "search.exclude": { 12 | "**/node_modules": true, 13 | "**/bower_components": true, 14 | "**/.env/**": true 15 | }, 16 | "python.pythonPath": "${workspaceFolder}/.env/bin/python" 17 | } 18 | -------------------------------------------------------------------------------- /remote-debugging-flask/README.md: -------------------------------------------------------------------------------- 1 | # Remote Debugging Sample (on the same Machine) 2 | 3 | ## Setup your remote environment 4 | ### Step 1: Open the workspace in your remote environment 5 | * This step will ensure you have setup Flask to be executed in the remote environment. 6 | 7 | ### Step 2: Configure VS Code to use a Python environment 8 | * Open a terminal window 9 | * Type the following command in the terminal window 10 | `virtualenv --python=python3.6 .env` 11 | * Reload VS Code using the command `Reload Window` (from your [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette)) 12 | * Open the file `app.py` 13 | * Select the command `Python: Select Interpteter` and select the Python environment created above (found in `./.env` directory created above) 14 | 15 | ### Step 3: Install Flask and PTVSD version 3.0.0 16 | * Open a terminal using the command [Python: Create Terminal](https://code.visualstudio.com/docs/python/environments#_activating-an-environment-in-the-terminal) (from your [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette)) 17 | * Enter the following command in the above terminal 18 | `python -m pip install flask ptvsd==3.0.0` 19 | 20 | ### Step 4: Start flask to be debugged 21 | * Run the Flask application 22 | * Option 1: 23 | * Go into the debugger menu and start debugging using the `Python: Flask` debug configuration. 24 | * Option 2: 25 | * Open a terminal using the command [Python: Create Terminal](https://code.visualstudio.com/docs/python/environments#_activating-an-environment-in-the-terminal) (from your [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette)) 26 | * Enter the following command in the above terminal 27 | `export FLASK_APP=app.py` 28 | `python -m flask run` 29 | * Wait for Flask to start in the terminal window 30 | * Once started you should see a message similar to the following in the terminal window: 31 | ```shell 32 | * Serving Flask app "app" 33 | * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) 34 | ``` 35 | 36 | ## Setup your local environment 37 | ### Step 1: Confirm flask is running 38 | * Identify the IP Address of your remote environment. 39 | * Open a browser window pointing to the Url that Flask is listening on (replacing the IP Address in the url) 40 | * Confirm the output on the browser window is `Hello World!` 41 | 42 | ### Step 2: Open the workspace in your local environment 43 | * This step will ensure you have your local environment setup to debug the remote flask application. 44 | * You do not to setup the Python environment or Flask locally to debug a remote environment. 45 | 46 | ### Step 2: Update the IP Address in `launch.json` (`"host": "localhost"`) 47 | * Identify the IP Address of your remote environment. 48 | * Open `.vscode/launch.json` and replace the value of the setting `host` from `localhost` to the IP address identified earlier. 49 | 50 | ### Step 3: Update the remote folder in `launch.json` (`"remoteRoot": "${workspaceFolder}",`) 51 | * Identify the full path to the directory containing the file `sample.py` in your remote environment. 52 | * Open `.vscode/launch.json` and replace the value of the setting `remoteRoot` from `${workspaceFolder}` to the path identified earlier. 53 | 54 | ### Step 4: Attach the debugger 55 | * Go into the debugger menu and select `Python: Attach` and press the green arrow icon 56 | * Open the `app.py` file and add a break point to the line `return "Hello World!"` 57 | * Refresh your browser window. 58 | * The debugger should hit the breakpoint. 59 | -------------------------------------------------------------------------------- /remote-debugging-flask/app.py: -------------------------------------------------------------------------------- 1 | import ptvsd 2 | address = ('0.0.0.0', 3000) 3 | ptvsd.enable_attach('my_secret', address) 4 | 5 | from flask import Flask 6 | app = Flask(__name__) 7 | 8 | @app.route('/') 9 | def hello(): 10 | return "Hello World!" 11 | 12 | if __name__ == '__main__': 13 | app.run() 14 | -------------------------------------------------------------------------------- /remote-debugging-locally/.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/settings.json 2 | -------------------------------------------------------------------------------- /remote-debugging-locally/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Python: Attach", 9 | "type": "python", 10 | "request": "attach", 11 | "localRoot": "${workspaceFolder}", 12 | "remoteRoot": "${workspaceFolder}", 13 | "port": 3000, 14 | "secret": "my_secret", 15 | "host": "localhost" 16 | }, 17 | { 18 | "name": "Python: Terminal (integrated)", 19 | "type": "python", 20 | "request": "launch", 21 | "stopOnEntry": true, 22 | "pythonPath": "${config:python.pythonPath}", 23 | "program": "${file}", 24 | "cwd": "", 25 | "console": "integratedTerminal", 26 | "env": {}, 27 | "envFile": "${workspaceFolder}/.env", 28 | "debugOptions": [], 29 | "internalConsoleOptions": "neverOpen" 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /remote-debugging-locally/README.md: -------------------------------------------------------------------------------- 1 | # Remote Debugging Sample (on the same Machine) 2 | 3 | ### Step 1: Configure VS Code to use a Python environment 4 | * Open a terminal window 5 | * Type the following command in the terminal window 6 | `virtualenv --python=python3.6 .env` 7 | * Reload VS Code using the command `Reload Window` (from your [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette)) 8 | * Open the file `sample.py` 9 | * Select the command `Python: Select Interpteter` and select the Python environment created above (found in `./.env` directory created above) 10 | 11 | ### Step 2: Install PTVSD version 3.0.0 12 | * Open a terminal using the command [Python: Create Terminal](https://code.visualstudio.com/docs/python/environments#_activating-an-environment-in-the-terminal) (from your [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette)) 13 | * Enter the following command in the above terminal 14 | `python -m pip install ptvsd==3.0.0` 15 | 16 | ### Step 3: Start program to be debugged 17 | * Run the file `sample.py` in the Python environment containing PTVSD 18 | * Option 1: 19 | * Open the file `sample.py` 20 | * Right click on editor window and select the menu `Run Python File in Terminal` 21 | * Option 2: 22 | * Open a terminal using the command [Python: Create Terminal](https://code.visualstudio.com/docs/python/environments#_activating-an-environment-in-the-terminal) (from your [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette)) 23 | * Enter the following command in the above terminal 24 | `python sample.py` 25 | * Now, the above program is running and waiting for a debugger to attach to it 26 | 27 | ### Step 4: Attaching the debugger 28 | * Open `sample.py` 29 | * Add a breakpoint to the line `print("attached")` 30 | * Go into the debugger menu and select `Python: Attach` and press the green arrow icon 31 | * Wait for around 2 seconds and the debugger should hit at the breakpoint 32 | 33 | ### Troubleshooting 34 | * Have you started the `sample.py`? 35 | * Check whether the debugger is listening on port 3000 using the commands 36 | * Use a command line tool such as `netstat` or any other 37 | * `netstat -an -p tcp | grep 3000` or `netstat -ano | find "3000"` 38 | * Check whether you are able to connect to the above port 39 | * Use a command line tool such as `telnet` or `nc` or any other 40 | * `telnet 127.0.0.1 3000` or `nc 127.0.0.1 3000` 41 | -------------------------------------------------------------------------------- /remote-debugging-locally/sample.py: -------------------------------------------------------------------------------- 1 | import ptvsd 2 | import time 3 | import os 4 | 5 | print(os.curdir) 6 | print("Waiting to attach") 7 | 8 | address = ('0.0.0.0', 3000) 9 | ptvsd.enable_attach('my_secret', address) 10 | ptvsd.wait_for_attach() 11 | 12 | time.sleep(2) 13 | 14 | print("attached") 15 | print("end") 16 | -------------------------------------------------------------------------------- /remote-debugging/.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/settings.json 2 | -------------------------------------------------------------------------------- /remote-debugging/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Python: Attach", 9 | "type": "python", 10 | "request": "attach", 11 | "localRoot": "${workspaceFolder}", 12 | "remoteRoot": "${workspaceFolder}", 13 | "port": 3000, 14 | "secret": "my_secret", 15 | "host": "localhost" 16 | }, 17 | { 18 | "name": "Python: Terminal (integrated)", 19 | "type": "python", 20 | "request": "launch", 21 | "stopOnEntry": true, 22 | "pythonPath": "${config:python.pythonPath}", 23 | "program": "${file}", 24 | "cwd": "", 25 | "console": "integratedTerminal", 26 | "env": {}, 27 | "envFile": "${workspaceFolder}/.env", 28 | "debugOptions": [], 29 | "internalConsoleOptions": "neverOpen" 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /remote-debugging/README.md: -------------------------------------------------------------------------------- 1 | # Remote Debugging Sample (on the same Machine) 2 | 3 | ## Setup your remote environment 4 | ### Step 1: Open the workspace in your remote environment 5 | * This step will ensure you have setup the program to be executed in the remote environment. 6 | 7 | ### Step 2: Configure VS Code to use a Python environment 8 | * Open a terminal window 9 | * Type the following command in the terminal window 10 | `virtualenv --python=python3.6 .env` 11 | * Reload VS Code using the command `Reload Window` (from your [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette)) 12 | * Open the file `sample.py` 13 | * Select the command `Python: Select Interpteter` and select the Python environment created above (found in `./.env` directory created above) 14 | 15 | ### Step 3: Install PTVSD version 3.0.0 16 | * Open a terminal using the command [Python: Create Terminal](https://code.visualstudio.com/docs/python/environments#_activating-an-environment-in-the-terminal) (from your [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette)) 17 | * Enter the following command in the above terminal 18 | `python -m pip install ptvsd==3.0.0` 19 | 20 | ### Step 4: Start program to be debugged 21 | * Run the file `sample.py` in the Python environment containing PTVSD 22 | * Option 1: 23 | * Open the file `sample.py` 24 | * Right click on editor window and select the menu `Run Python File in Terminal` 25 | * Option 2: 26 | * Open a terminal using the command [Python: Create Terminal](https://code.visualstudio.com/docs/python/environments#_activating-an-environment-in-the-terminal) (from your [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette)) 27 | * Enter the following command in the above terminal 28 | `python sample.py` 29 | * Now, the above program is running and waiting for a debugger to attach to it 30 | 31 | ## Setup your local environment 32 | ### Step 1: Open the workspace in your local environment 33 | * This step will ensure you have setup the program to be debugged locally. 34 | * You do not to setup the Python environment locally to debug a remote environment. 35 | 36 | ### Step 2: Update the IP Address in `launch.json` (`"host": "localhost"`) 37 | * Identify the IP Address of your remote environment. 38 | * Open `.vscode/launch.json` and replace the value of the setting `host` from `localhost` to the IP address identified earlier. 39 | 40 | ### Step 3: Update the remote folder in `launch.json` (`"remoteRoot": "${workspaceFolder}",`) 41 | * Identify the full path to the directory containing the file `sample.py` in your remote environment. 42 | * Open `.vscode/launch.json` and replace the value of the setting `remoteRoot` from `${workspaceFolder}` to the path identified earlier. 43 | 44 | ### Step 4: Attach the debugger 45 | * Open `sample.py` 46 | * Add a breakpoint to the line `print("attached")` 47 | * Go into the debugger menu and select `Python: Attach` and press the green arrow icon 48 | * Wait for around 2 seconds and the debugger should hit at the breakpoint 49 | 50 | ## Troubleshooting 51 | * Have you started the `sample.py`? 52 | * Check whether the debugger is listening on port 3000 using the commands 53 | * Use a command line tool such as `netstat` or any other 54 | * `netstat -an -p tcp | grep 3000` or `netstat -ano | find "3000"` 55 | * Check whether you are able to connect to the above port 56 | * Use a command line tool such as `telnet` or `nc` or any other 57 | * `telnet 3000` or `nc 3000` 58 | -------------------------------------------------------------------------------- /remote-debugging/sample.py: -------------------------------------------------------------------------------- 1 | import ptvsd 2 | import time 3 | import os 4 | 5 | print(os.curdir) 6 | print("Waiting to attach") 7 | 8 | address = ('0.0.0.0', 3000) 9 | ptvsd.enable_attach('my_secret', address) 10 | ptvsd.wait_for_attach() 11 | 12 | time.sleep(2) 13 | 14 | print("attached") 15 | print("end") 16 | -------------------------------------------------------------------------------- /sample-django/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Python: Django", 9 | "type": "python", 10 | "request": "launch", 11 | "program": "${workspaceFolder}/manage.py", 12 | "args": [ 13 | "runserver", 14 | "--noreload" 15 | ], 16 | "django": true 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /sample-django/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.pythonPath": "${workspaceFolder}/.env/bin/python" 3 | } -------------------------------------------------------------------------------- /sample-django/README.md: -------------------------------------------------------------------------------- 1 | # Django Debugging Sample 2 | 3 | **Note:** 4 | This sample uses Python 3.6 and Django 2.0 5 | This is a sample Django application created using [tutorial](https://docs.djangoproject.com/en/2.0/intro/tutorial01/) on the Django website 6 | 7 | ### Step 1: Configure VS Code to use a Python environment 8 | * Open a terminal window 9 | * Type the following command in the terminal window 10 | `virtualenv --python=python3.6 .env` 11 | * Reload VS Code using the command `Reload Window` (from your [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette)) 12 | * Open the file `sample.py` 13 | * Select the command `Python: Select Interpteter` and select the Python environment created above (found in `./.env` directory created above) 14 | 15 | ### Step 2: Install Django 16 | * Open a terminal using the command [Python: Create Terminal](https://code.visualstudio.com/docs/python/environments#_activating-an-environment-in-the-terminal) (from your [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette)) 17 | * Enter the following command in the above terminal 18 | `python -m pip install -r requirements.txt` 19 | 20 | ### Step 3: Launch Django in debug mode 21 | * Go into the debugger menu and start debugging using the `Python: Django` debug configuration. 22 | * Wait for Django to start in the terminal window 23 | * Once started you should see something similar to the following in the terminal window: 24 | ```shell 25 | Starting development server at http://127.0.0.1:8000/ 26 | Quit the server with CONTROL-C. 27 | ``` 28 | 29 | ### Step 4: Confirm Django is running 30 | * Open a browser window pointing to the Url that Django is listening on 31 | * Confirm Django home page appears 32 | * Next navigate to the `polls` page ([http://127.0.0.1:8000/polls](http://127.0.0.1:8000/polls)) 33 | * Confirm the output on the browser window is `Hello, world. You're at the polls index.` 34 | 35 | ### Step 5: Debug Django 36 | * Open the `polls/views.py` file and add a break point to the line `return HttpResponse("Hello, world. You're at the polls index.")` 37 | * Refresh your browser window. 38 | * The debugger should hit the breakpoint. 39 | -------------------------------------------------------------------------------- /sample-django/home/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DonJayamanne/vscode-python-samples/8b78d3048333f5f67484ed9d0716892633cda574/sample-django/home/__init__.py -------------------------------------------------------------------------------- /sample-django/home/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /sample-django/home/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class HomeConfig(AppConfig): 5 | name = 'home' 6 | -------------------------------------------------------------------------------- /sample-django/home/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DonJayamanne/vscode-python-samples/8b78d3048333f5f67484ed9d0716892633cda574/sample-django/home/migrations/__init__.py -------------------------------------------------------------------------------- /sample-django/home/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /sample-django/home/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | My Home Page 5 | 6 | 7 |

Sample Django Application

8 |

{{ value_from_server }}

9 |

{{ another_value_from_server }}

10 | 11 | 12 | -------------------------------------------------------------------------------- /sample-django/home/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /sample-django/home/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | 3 | from . import views 4 | 5 | urlpatterns = [ 6 | path('', views.index, name='index'), 7 | ] 8 | -------------------------------------------------------------------------------- /sample-django/home/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from django.template import loader 3 | 4 | 5 | def index(request): 6 | context = { 7 | 'value_from_server':'one', 8 | 'another_value_from_server':'two' 9 | } 10 | return render(request, 'index.html', context) 11 | 12 | # from django.shortcuts import render 13 | # from django.shortcuts import render_to_response 14 | # # Create your views here. 15 | # from django.http import HttpResponse 16 | 17 | 18 | # def index(request): 19 | # return render_to_response('index.html', context={'value_from_server':'one', 'another_value_from_server':'two'}) 20 | # #return HttpResponse("Hello, world. You're at the home index.") 21 | -------------------------------------------------------------------------------- /sample-django/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError: 10 | # The above import may fail for some other reason. Ensure that the 11 | # issue is really that Django is missing to avoid masking other 12 | # exceptions on Python 2. 13 | try: 14 | import django 15 | except ImportError: 16 | raise ImportError( 17 | "Couldn't import Django. Are you sure it's installed and " 18 | "available on your PYTHONPATH environment variable? Did you " 19 | "forget to activate a virtual environment?" 20 | ) 21 | raise 22 | execute_from_command_line(sys.argv) 23 | -------------------------------------------------------------------------------- /sample-django/mysite/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DonJayamanne/vscode-python-samples/8b78d3048333f5f67484ed9d0716892633cda574/sample-django/mysite/__init__.py -------------------------------------------------------------------------------- /sample-django/mysite/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for mysite project. 3 | 4 | Generated by 'django-admin startproject' using Django 1.11.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.11/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/1.11/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = '5u06*)07dvd+=kn)zqp8#b0^qt@*$8=nnjc&&0lzfc28(wns&l' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | ] 41 | 42 | MIDDLEWARE = [ 43 | 'django.middleware.security.SecurityMiddleware', 44 | 'django.contrib.sessions.middleware.SessionMiddleware', 45 | 'django.middleware.common.CommonMiddleware', 46 | 'django.middleware.csrf.CsrfViewMiddleware', 47 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 48 | 'django.contrib.messages.middleware.MessageMiddleware', 49 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 50 | ] 51 | 52 | ROOT_URLCONF = 'mysite.urls' 53 | 54 | TEMPLATES = [ 55 | { 56 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 57 | 'DIRS': ['home/templates'], 58 | 'APP_DIRS': True, 59 | 'OPTIONS': { 60 | 'context_processors': [ 61 | 'django.template.context_processors.debug', 62 | 'django.template.context_processors.request', 63 | 'django.contrib.auth.context_processors.auth', 64 | 'django.contrib.messages.context_processors.messages', 65 | ], 66 | }, 67 | }, 68 | ] 69 | 70 | WSGI_APPLICATION = 'mysite.wsgi.application' 71 | 72 | 73 | # Database 74 | # https://docs.djangoproject.com/en/1.11/ref/settings/#databases 75 | 76 | DATABASES = { 77 | 'default': { 78 | 'ENGINE': 'django.db.backends.sqlite3', 79 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 80 | } 81 | } 82 | 83 | 84 | # Password validation 85 | # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators 86 | 87 | AUTH_PASSWORD_VALIDATORS = [ 88 | { 89 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 90 | }, 91 | { 92 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 93 | }, 94 | { 95 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 96 | }, 97 | { 98 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 99 | }, 100 | ] 101 | 102 | 103 | # Internationalization 104 | # https://docs.djangoproject.com/en/1.11/topics/i18n/ 105 | 106 | LANGUAGE_CODE = 'en-us' 107 | 108 | TIME_ZONE = 'UTC' 109 | 110 | USE_I18N = True 111 | 112 | USE_L10N = True 113 | 114 | USE_TZ = True 115 | 116 | 117 | # Static files (CSS, JavaScript, Images) 118 | # https://docs.djangoproject.com/en/1.11/howto/static-files/ 119 | 120 | STATIC_URL = '/static/' 121 | -------------------------------------------------------------------------------- /sample-django/mysite/urls.py: -------------------------------------------------------------------------------- 1 | """mysite URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/1.11/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.conf.urls import url, include 14 | 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 15 | """ 16 | from django.conf.urls import url, include 17 | from django.contrib import admin 18 | from django.views.generic import RedirectView 19 | 20 | urlpatterns = [ 21 | url(r'^home/', include('home.urls')), 22 | url(r'^admin/', admin.site.urls), 23 | url('', RedirectView.as_view(url='/home/')), 24 | ] 25 | -------------------------------------------------------------------------------- /sample-django/mysite/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for mysite project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /sample-django/requirements.txt: -------------------------------------------------------------------------------- 1 | Django==2.0.2 2 | -------------------------------------------------------------------------------- /sample-flask/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Python: Flask", 9 | "type": "python", 10 | "request": "launch", 11 | "stopOnEntry": false, 12 | "pythonPath": "${config:python.pythonPath}", 13 | "module": "flask", 14 | "cwd": "${workspaceFolder}", 15 | "env": { 16 | "FLASK_APP": "${workspaceFolder}/app.py" 17 | }, 18 | "args": [ 19 | "run", 20 | "--no-debugger", 21 | "--no-reload" 22 | ], 23 | "envFile": "${workspaceFolder}/.env", 24 | "debugOptions": [ 25 | "RedirectOutput" 26 | ], 27 | "console": "integratedTerminal", 28 | "internalConsoleOptions": "neverOpen" 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /sample-flask/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.exclude": { 3 | "**/.git": true, 4 | "**/.svn": true, 5 | "**/.hg": true, 6 | "**/CVS": true, 7 | "**/.DS_Store": true, 8 | "**/__pycache__/**": true, 9 | "**/.pyc": true 10 | }, 11 | "search.exclude": { 12 | "**/node_modules": true, 13 | "**/bower_components": true, 14 | "**/.env/**": true 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sample-flask/README.md: -------------------------------------------------------------------------------- 1 | # Flask Debugging Sample 2 | 3 | ### Step 1: Configure VS Code to use a Python environment 4 | * Open a terminal window 5 | * Type the following command in the terminal window 6 | `virtualenv --python=python3.6 .env` 7 | * Reload VS Code using the command `Reload Window` (from your [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette)) 8 | * Open the file `sample.py` 9 | * Select the command `Python: Select Interpteter` and select the Python environment created above (found in `./.env` directory created above) 10 | 11 | ### Step 2: Install Flask 12 | * Open a terminal using the command [Python: Create Terminal](https://code.visualstudio.com/docs/python/environments#_activating-an-environment-in-the-terminal) (from your [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette)) 13 | * Enter the following command in the above terminal 14 | `python -m pip install flask` 15 | 16 | ### Step 3: Launch Flask in debug mode 17 | * Go into the debugger menu and start debugging using the `Python: Flask` debug configuration. 18 | * Wait for Flask to start in the terminal window 19 | * Once started you should see something similar to the following in the terminal window: 20 | ```shell 21 | * Serving Flask app "app" 22 | * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) 23 | ``` 24 | 25 | ### Step 4: Confirm flask is running 26 | * Open a browser window pointing to the Url that Flask is listening on 27 | * Confirm the output on the browser window is `Hello World!` 28 | 29 | ### Step 5: Debug Flask 30 | * Open the `app.py` file and add a break point to the line `return "Hello World!"` 31 | * Refresh your browser window. 32 | * The debugger should hit the breakpoint. 33 | 34 | ### Troubleshooting 35 | * Confirm flask is running in the terminal window. 36 | * Confirm you can see `Hello World!` in the browser widnow. 37 | * Try running flask manually and testing it as follows (in your terminal window): 38 | ```shell 39 | $ export FLASK_APP=app.py 40 | $ python -m flask run 41 | * Serving Flask app "app" 42 | * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) 43 | ``` 44 | -------------------------------------------------------------------------------- /sample-flask/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | app = Flask(__name__) 3 | 4 | @app.route('/') 5 | def hello(): 6 | return "Hello World!" 7 | 8 | if __name__ == '__main__': 9 | app.run() 10 | -------------------------------------------------------------------------------- /samples.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | }, 6 | { 7 | "path": "remote-debugging" 8 | }, 9 | { 10 | "path": "remote-debugging-locally" 11 | }, 12 | { 13 | "path": "sample-flask" 14 | }, 15 | { 16 | "path": "remote-debugging-flask" 17 | }, 18 | { 19 | "path": "remote-debugging-docker" 20 | }, 21 | { 22 | "path": "sample-django" 23 | }, 24 | { 25 | "path": "remote-debugging-docker-django" 26 | } 27 | ], 28 | "settings": { 29 | "files.exclude": { 30 | "**/.git": true, 31 | "**/.svn": true, 32 | "**/.hg": true, 33 | "**/CVS": true, 34 | "**/.DS_Store": true, 35 | "**/__pycache__/**": true, 36 | "**/.pyc": true 37 | }, 38 | "search.exclude": { 39 | "**/node_modules": true, 40 | "**/bower_components": true, 41 | "**/.env/**": true 42 | } 43 | } 44 | } 45 | --------------------------------------------------------------------------------