How To Debug a Django Application in VS CODE (Visual Studio Code)
HTML-код
- Опубликовано: 8 фев 2025
- Set breakpoints and debug a live Django Application!
Here's the code snippet for the VS Code configuration you will need to debug a Django app.
{
"name": "BlogTheData",
"python": "/Users/johnsolly/Documents/code/blogthedata/venv/bin/python3",
"type": "python",
"request": "launch",
"program": "/Users/johnsolly/Documents/code/blogthedata/django_project/manage.py",
"console": "internalConsole",
"args": ["runserver"],
"django": true,
"justMyCode": true,
}
And here is a link to Corey Schafer's Django Tutorials (Create your own Django App!)
• Django Tutorials
Time Stamps
05:05 - How to set up the VS Code configuration
wow !!!! right to the point and straight forward. saved me probably like 5 hours of researching and trying to work it out. thank you so much!
Actual debugging starts @ 4:55
Spend several hours investigating around. Finally found out that your solution works!!!
Thanks for this, very helpful now that I'm back into developing on my Wagtail CMS, which is Django based. This worked perfectly and will greatly increase my productivity. Cheers!
Thanks, exactly what I was looking for.
I instantally subscribed. Bro Keep posting. I got you !!!
Trying to figure this out took me hours! Thank you!
thanks it helped a lot
You're the best!Thank you!
Than you. It's exactly what I was looking for.
Short and concise, very good
Great video, short and works perfectly
Just learned if you add "django": true to your config, you can debug the django HTML templates! See -> code.visualstudio.com/docs/python/debugging under 'Specific app types"
You might also want to add these two lines of code to the end of your test file so you can re-run the test after hitting a breakpoint.
Man you are hero
thank you very much
How to do if Django is running in a docker ?
Great Content ! I have a question , How to debug Django inside docker ? I use nginx as web server.
its not working sir i placed the breakpoint and through the debug console gave the link but doesnt it the breakpoint. why?
How can I debug it on WSL
great video but not working in window based visual studio django ...i dont know why
I have the same issue
Great video very clear thanks. I didn't know the corey's tutorial (thanks for the link).
i just don't understand how to debug generic views, because in views.py instead of return render (....) you have just a class declaration. A good example is in the tutorial of thenewboston chap 29 on youtube (best tutorial serie i've seen) :
ruclips.net/video/c3yB0_4Yd48/видео.html&ab_channel=thenewboston
At 2:20 he changes views for generic views but i haven't found how to debug that.
Thanks for the comment Oliver! I haven't actually used generic views before, but my SearchView is using that return render (....) way of doing things instead of using a class.
def SearchView(request):
cat_list = Category.objects.all()
if request.method == 'POST':
searched = request.POST['searched']
filtered_posts = Post.objects.filter(Q(content__icontains=searched) | Q(title__icontains=searched))
return render(
request,
"blog/search_posts.html",
{"cat_list": cat_list, "searched": searched, "filtered_posts": filtered_posts},
)
else:
return render(
request,
"blog/search_posts.html",
{"cat_list": cat_list},
)
When you say, 'I don't understand how to debug generic views' what part are you trying to get at that you can't catch with a breakpoint? I will admit sometimes it feels like I can't debug what is going into the Jinja template.
Also, I love @thenewboston and I've seen a bunch of his generic Python videos. I'll need to look into his Django stuff too!