调试在 VS Studio Code Django 中不起作用
Debugging not working in VS Studio Code Django
我一直在努力解决 official Django Tutorial in Visual Studio Code 但我遇到了 运行 问题。目前,当我在 now = datetime.now
行设置断点时,调试器似乎无法到达它。
我的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"),
]
我的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)
您必须在调试器转到断点之前启动 运行 连接服务器。一旦你按下 运行 等待它完成,然后转到 http://127.0.0.1:8000/hello/VSCode。之后调试器将转到您的断点。
我一直在努力解决 official Django Tutorial in Visual Studio Code 但我遇到了 运行 问题。目前,当我在 now = datetime.now
行设置断点时,调试器似乎无法到达它。
我的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"),
]
我的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)
您必须在调试器转到断点之前启动 运行 连接服务器。一旦你按下 运行 等待它完成,然后转到 http://127.0.0.1:8000/hello/VSCode。之后调试器将转到您的断点。