我正在开发一个django应用程序,包括使用Visual Studio Code的自定义逻辑代码,我想通过django shell在interactie中调试我的代码。这是可能的,如果是这样,需要什么调试设置?
Shell是shell,VSCode是VSCode。您无法从shell调试代码。
当我需要调试我的自定义Django代码时,我将debug.py
文件放在我的项目根目录(其中manage.py
是)并手动加载我的Django项目,即我模仿Django shell。
# Here you should use all the logic that you have
# in manage.py before execute_from_command_line(sys.argv)
# Generally there is only settings module set up:
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
# Initialize django application
import django
django.setup()
# Do what you want to debug and set breakpoints
from django.contrib.auth.models import User
User.objects.exists()
然后使用常规的Python: Current file
调试选项运行此文件