can not debugging in django
See original GitHub issueI tried to use IPDB in a Django project, but found that it would cause the program to stop.
from django.http import HttpResponse
# Create your views here.
def home(request):
import ipdb
ipdb.set_trace()
return HttpResponse("ok")
When the program reaches the breakpoint, it pauses for a moment and then crash.
(python3.7) ➜ blog python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 3 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
June 17, 2019 - 16:14:42
Django version 2.2.2, using settings 'blog.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
> /home/user/project/django_example/blog/user/views.py(9)home()
7 import ipdb
8 ipdb.set_trace()
----> 9 return HttpResponse("ok")
ipdb> Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 60, in execute
super().execute(*args, **options)
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 95, in handle
self.run(**options)
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/django/utils/autoreload.py", line 585, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/django/utils/autoreload.py", line 570, in start_django
reloader.run(django_main_thread)
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/django/utils/autoreload.py", line 288, in run
self.run_loop()
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/django/utils/autoreload.py", line 294, in run_loop
next(ticker)
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/django/utils/autoreload.py", line 334, in tick
for filepath, mtime in self.snapshot_files():
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/django/utils/autoreload.py", line 350, in snapshot_files
for file in self.watched_files():
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/django/utils/autoreload.py", line 249, in watched_files
yield from iter_all_python_module_files()
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/django/utils/autoreload.py", line 103, in iter_all_python_module_files
return iter_modules_and_files(modules, frozenset(_error_files))
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/django/utils/autoreload.py", line 120, in iter_modules_and_files
sys_file_paths.append(module.__file__)
AttributeError: module '__main__' has no attribute '__file__'
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@python.org
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
%config Application.verbose_crash=True
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/IPython/core/history.py", line 780, in writeout_cache
self._writeout_input_cache(conn)
File "/home/user/.virtualenvs/python3.7/lib/python3.7/site-packages/IPython/core/history.py", line 764, in _writeout_input_cache
(self.session_number,)+line)
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 140378414733056 and this is thread id 140378526684928.
(python3.7) ➜ blog
my pc system is ubuntu 16.04 and
Django==2.2.2
ipdb==0.12
ipython==7.5.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How to debug in Django, the good way? - Stack Overflow
Just click to the left of a line and hit the debug button. It works well for Django source code too if you...
Read more >Django debugging not stopping on breakpoint #82002 - GitHub
While debugging, python django, debugging does not trip on Breakpoints as if they are not there at all.. Launch.json { // Use IntelliSense ......
Read more >Debug Django templates | PyCharm Documentation - JetBrains
Debugging a Django template: launch debug configuration. Click the link in the Debug tool window. A browser window will open with a Page...
Read more >When im run the Django project in debug mode it's show the ...
The only explanation I have for this is that the active environment when you run pip list is not the env folder you...
Read more >Debugging a Containerized Django App in VS Code
Here, we first determine if the project is running in DEBUG mode. If so, we then make sure that the debugger is not...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
pdb works for me
@hvdklauw Thanks for follow up