Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
656 views
in Technique[技术] by (71.8m points)

how do i debug/breakpoint my django app using pycharm?

I'm trying to work out how to run the debug stuff that pycharm seems to offer (well, it allows me to set breakpoints, anyway, so i'm assuming there's a nice gui for it)

I've concluded that i cannot use the ctrl-shift-r and then "runserver" command, and that instead i'd need to setup a "run configuration"? I made a "django server" one, but i don't know what values to put etc. When i run it, it tells me that some setting is wrong - i'm pretty sure it isn't, because the standard "runserver" command works fine.

And that's about all i concluded. If there is a nifty tutorial or steps to get it so i can

  1. put in a break point
  2. go to the page that triggers that breakpoint and follow the code's inner working in pycharm

i'd be thrilled!

cheers!

UPDATE: in case you're wondering, here is the error i got:

Traceback (most recent call last):

File "manage.py", line 11, in import settings

File "C:developmentPycharmProjectsdumpstownsettings.py", line 185, in add_to_builtins('gravatar.templatetags.gravatar')

File "C:developmentpythonlibsite-packagesdjangoemplatease.py", line 1017, in add_to_builtins

builtins.append(import_library(module))

File "C:developmentpythonlibsite-packagesdjangoemplatease.py", line 963, in import_library

raise InvalidTemplateLibrary("ImportError raised loading %s: %s" % (taglib_module, e))

django.template.base.InvalidTemplateLibrary: ImportError raised loading gravatar.templatetags.gravatar: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

Where the application itself, on a "runserver" never has any issues.

UPDATE: as per my answer below, pycharm is broken for add_to_builtins.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. Setup your virtual environment

    1. Create or open your project in PyCharm
    2. Go to File - Settings in the menu (or just click on the settings icon)
    3. Go to Python Interpreter
    4. Click on Add in the top
    5. Go to the bin folder where you created the virtual environment and select python
  2. Set a breakpoint

    1. Next to the line of code you want to set the breakpoint. To the left there is usually a grey line. Usually next to the line numbers. Just click there and a big red dot will appear. Looks like this
  3. Hit the Run in debug mode button.

    1. Next to the Green play button there is a button with a bug on it. Use that to launch the runserver in debug mode. Now when you use your web application and the code hits the breakpoint it will stop there and you will be able to step in and over or resume in pycharm.

      • If you still are not able to debug you might need to edit the pycharm project config. You can do that like this.

You can look at http://garmoncheg.blogspot.it/2012/01/establishing-dev-environment-with.html too


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...