python - 调试在 VS Studio Code Django 中不起作用
问题描述
我一直在使用 Visual Studio Code 中的官方 Django 教程,但遇到了一个问题。目前,当我在该行设置断点时,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"),
]
我的意见.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。之后,调试器将转到您的断点。
推荐阅读
- mysql - 比较同一列MYSQL中的日期
- python - python start_new_thread 正在打印无
- c++ - 让 ImGui 与 Vulkan 一起工作时遇到问题
- javascript - 将本地 glTF 文件加载到 Javascript 内存中
- c++ - 将 SDL2/SD2_image 与 CMake 静态链接
- r - 无法理解 R 的这种语法
- google-cloud-firestore - 如何在 Redux Saga 内的 Firestore 中获取来自不同集合的文档
- java - 如何使用 Java 在 Android Studio 中的一个日期选择器中制作多个日期选择器?
- python-3.x - IMAP4LIB 使用 store 命令时出现错误“BAD [b'Could not parse command']”
- linux - 在文件中查找文本并将其复制到另一个路径(linux 命令)