elpy
elpy copied to clipboard
Django command shell: buffer unresponsive when `runserver` also active
Summary
I cannot interact with the python mange.py shell
buffer created with C-c C-x c shell RET
The buffer is unresponsive and does not type anything in the buffer.
Steps to reproduce
C-c C-x r
C-c C-x c shell RET
My configuration
OS
Ubuntu 18
Emacs 26.3
Result of (elpy-config)
Virtualenv........: venv (/home/jon/Desktop/scratch/django/django-book-tutorial/venv)
RPC Python........: 3.7.2 (/home/jon/Desktop/scratch/django/django-book-tutorial/venv/bin/python)
Interactive Python: python3 (/home/jon/Desktop/scratch/django/django-book-tutorial/venv/bin/python3)
Emacs.............: 26.3
Elpy..............: 1.28.0
Jedi..............: 0.15.1
Rope..............: Not found (0.14.0 available)
Autopep8..........: Not found (1.4.4 available)
Yapf..............: Not found (0.28.0 available)
Black.............: Not found (19.3b0 available)
Syntax checker....: Not found (flake8)
Elpy configuration in my init.el
(setq python-shell-interpreter "python3"
python-indent-offset 4)
(elpy-enable)
(defun pyvenv-venv-dwim ()
"Ask to activate a virtual environment or deactivate one if active."
(interactive)
(if pyvenv-virtual-env
(pyvenv-deactivate)
(call-interactively 'pyvenv-activate)))
(add-hook 'elpy-mode-hook (lambda () (define-key elpy-mode-map (kbd "C-c v") 'pyvenv-venv-dwim)))
As far as I am aware, Elpy doesn't support interacting with the commands sent to django.
I see a way to make it work, but only with Python (not IPython).
Is it working if you overwrite elpy-django-command
with the following updated version ?
(defun elpy-django-command (cmd)
"Prompt user for Django command. If called with `C-u',
it will prompt for other flags/arguments to run."
(interactive (list (completing-read "Command: " (elpy-django--get-commands) nil nil)))
;; Called with C-u, variable is set or is a cmd that requires an argument
(when (or current-prefix-arg
elpy-django-always-prompt
(member cmd elpy-django-commands-with-req-arg))
(setq cmd (concat cmd " " (read-shell-command (concat cmd ": ") "--noinput"))))
(if (string= cmd "shell")
(run-python (concat elpy-django-command " " cmd " -i python")
t t)
(compile (concat elpy-django-command " " cmd))))
@galaunay yes, it is working for me, I dont use Ipython so this is good for me.. Thanks
EDIT: It'd be nice to include this new function in Elpy for people who learn python with Django and are reading the django manual on their website. Imagine they come accross the section in the django manual where it asks them to interact with the django shell but they are not able to type in it (just as it happened to me).
It'd be cool to mention this in the Elpy docs as a gateway for Python people to learn how to use Emacs.
What do you think? Would it'd be better to create small videos for this or gifs that show how to use Elpy and Django? I could probably work on any of those two. Let me know.
Good to know, thanks for noticing it was not working in the first place.
EDIT: It'd be nice to include this new function in Elpy for people who learn python with Django and are reading the django manual on their website.
I was thinking about making this the default behaviour in Elpy. In my opinion, there is no point starting a shell if we cannot interact with it. I will just add a note in the documentation to explain why we use python instead of ipython.
What do you think? Would it'd be better to create small videos for this or gifs that show how to use Elpy and Django? I could probably work on any of those two. Let me know.
We started thinking about producing small videos to present Elpy's features with @sten0 (see #1603). We could definitely use some help if you are willing to do one for Django. Would you be interested ?
Note: I just realised there was other interactive django commands (like dbshell
) that will not work in Elpy without additional work.