FLASK won't reload after changing code in VS Code - flask

My editor is vs code, I am running flask with the below config
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "application.py",
"FLASK_ENV": "development",
"DATABASE_URL": "postgres://localhost/cs50w_project1_development",
"FLASK_DEBUG": 1,
"SECRET_KEY": "abcefefe"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true
},
It seems all good except flask won't hot reload when I am changing the code. E.G., add an action.
I have to manually reload the flask by clicking the restart button.
Is there any issue with my current config?

Remove the --no-reload in the launch.json. It's a very old thread but posting the answer here for future visitors.

Related

How to create and configure run.json in the new JetBrains Fleet?

I was trying how to create I / O for the new JetBrains' IDE called Fleet. But unfortunately couldn't do so. So, here I am asking the StackOverflow community "How can I configure the run.json file in Fleet".
What am I supposed to write in that file?
I am trying to code C++ file in Fleet.
This is what I came up with:
{
"configurations": [
{
"type": "command",
"name": "run",
"dependsOn": ["build"],
"program": "$PROJECT_DIR$/solution",
},
{
"type": "command",
"name": "build",
"program": "/usr/bin/g++",
"args": ["$PROJECT_DIR$/main.cpp", "-std=c++17", "-pthread", "-O2", "-o", "solution"],
},
]
}
It's called chained run configuration. You need separate build and run configs, and make the run config depend on the build config. Hope that helps :)

breakpoints on django-rest-framework project in vscode are not hit in debug mode

I have django-rest project on my vscode.The problem is that when I run the project in debug mode the breakpoints are not catched!!. I just get response without being stopped on that specific breakpoint.
This is my launch.json file
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\\manage.py",
"args": [
"runserver"
],
"django": true,
"justMyCode": true
}
]
}
BTW I send the requests by swagger!
I have also tried postman and got the same result!
(just got the response without the code being stopped on this view )
I send the requests to ManageUserView

How do I reach a containerized django web app running in visual studio code debug mode?

After some path changes due to being a git submodule, I was able to configure a launch.json and tasks.json to get my application running in debug mode. Here are the tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-build",
"label": "docker-build",
"platform": "python",
"dockerBuild": {
"tag": "signmeasures:latest",
"dockerfile": "${workspaceFolder}/signmeasures-frontend/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": [
"docker-build"
],
"python": {
"args": [
"runserver",
"0.0.0.0:8000",
"--nothreading",
"--noreload"
],
"file": "signmeasures-frontend/signmeasures/manage.py"
}
}
]
}
and here is the launch.json
{
"configurations": [
{
"name": "Docker: Python - Django",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"python": {
"pathMappings": [
{
"localRoot": "${workspaceFolder}/signmeasures-frontend",
"remoteRoot": "/app"
}
],
"projectType": "django",
"port": 5678,
"host": "localhost"
},
}
]
}
I'm not too familiar with setting up the debug container or docker in general, I'm still trying to learn. When I hit the debug button on the debug tab, it builds a container and then in the debug console I see this
but when I try to go to localhost:8000 it does not load the web app. It shows this:
I'm not sure what I need to change to be able to reach it and set breakpoints to debug this application. What should I do to be able to reach it and debug?

Setup the VSCode debugger for python 2.7 and Django 1.11

I already setup a debugger for an existing django 1,11 project on vscode with the Microsoft python extension, but this will only works on http://127.0.0.1:5000/ (the homepage) I need this debugger to be hooked to my already running server on http://localhost:8000/
I need a setup that allows me to debug on vscode, make the code stop at specific breakpoints, debug code for various URLs using google chrome.
This is my launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"django": true
}
]
}
Python 2.7
Django 1.11
Visual Studio Code
MacOS Catalina
Please help.
Use 8000 as shown below in your setup
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
"8000",
"--noreload",
"--nothreading"
],
"django": true
}
]
}

Debugging Django in VSCode fails on imp.py

I am unable to debug my Django app. I am using virtualenv and have configured my VSCode workspace to point to the absolute path within my virtual environment for python.
"python.pythonPath": "/Users/Me/PyProjs/proj_env/bin/python"
When trying to debug, however, the editor jumps to the imp.py file (which is located at ~/proj_env/lib/python3.4) and fails at the new_module() method.
def new_module(name):
"""**DEPRECATED**
Create a new module.
The module is not entered into sys.modules.
"""
return types.ModuleType(name) #Editor breaks here.
Inspecting the name variable, I see it is set to "__main__". When stepping through, the editor exits debug mode and no errors or exceptions are logged in the Debug Console.
Anybody know what my issue could possibly be? I just want to debug my application!
You probably have stopOnEntry set to true in your launch.json. Try setting it to false:
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceFolder}/manage.py",
"cwd": "${workspaceFolder}",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"env": {},
"envFile": "${workspaceFolder}/.env",
"debugOptions": [
"RedirectOutput",
"DjangoDebugging"
]
},
Looks like a possible defect, check the VS Code Python GitHub repo: https://github.com/DonJayamanne/pythonVSCode/issues/1092