Debugging not working in VS Studio Code Django
Question:
I have been working through the official Django Tutorial in Visual Studio Code but I have run into an issue. Currently when I ever I set a break-point at the line now = datetime.now
the debugger seems to fail to reach it.
My urls.py:
from django.urls import path
from hello import views
urlpatterns = [
path("", views.home, name="home"),
path("hello/<name>", views.hello_there, name="hello_there"),
]
My views.py:
import re
from django.utils.timezone import datetime
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello, Django!")
def hello_there(request, name):
now = datetime.now()
formatted_now = now.strftime("%A, %d %B, %Y at %X")
# Filter the name argument to letters only using regular expressions. URL arguments
# can contain arbitrary text, so we restrict to safe characters only.
match_object = re.match("[a-zA-Z]+", name)
if match_object:
clean_name = match_object.group(0)
else:
clean_name = "Friend"
content = "Hello there, " + clean_name + "! It's " + formatted_now
return HttpResponse(content)
Answers:
You have to start running the sever before the debugger will go to the break-point. Once you press run wait until it is finished, and go to http://127.0.0.1:8000/hello/VSCode. After that the debugger will go to your breakpoint.
I know I’m late to the game here, but doing the same tutorial as he does and the break point does not work. It shows the red dot on left indicating the break point is set but when you run it (f5) in my case I set up a launch.json file to run the server anyways the program dies not stop on the break. It shows it’s there (empty donut or ring whatever) but does not break.
I have been working through the official Django Tutorial in Visual Studio Code but I have run into an issue. Currently when I ever I set a break-point at the line now = datetime.now
the debugger seems to fail to reach it.
My urls.py:
from django.urls import path
from hello import views
urlpatterns = [
path("", views.home, name="home"),
path("hello/<name>", views.hello_there, name="hello_there"),
]
My views.py:
import re
from django.utils.timezone import datetime
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello, Django!")
def hello_there(request, name):
now = datetime.now()
formatted_now = now.strftime("%A, %d %B, %Y at %X")
# Filter the name argument to letters only using regular expressions. URL arguments
# can contain arbitrary text, so we restrict to safe characters only.
match_object = re.match("[a-zA-Z]+", name)
if match_object:
clean_name = match_object.group(0)
else:
clean_name = "Friend"
content = "Hello there, " + clean_name + "! It's " + formatted_now
return HttpResponse(content)
You have to start running the sever before the debugger will go to the break-point. Once you press run wait until it is finished, and go to http://127.0.0.1:8000/hello/VSCode. After that the debugger will go to your breakpoint.
I know I’m late to the game here, but doing the same tutorial as he does and the break point does not work. It shows the red dot on left indicating the break point is set but when you run it (f5) in my case I set up a launch.json file to run the server anyways the program dies not stop on the break. It shows it’s there (empty donut or ring whatever) but does not break.