(defun django-shell () (interactive) (let ((python-shell-interpreter (read-file-name "Locate manage.py ")) (python-shell-interpreter-args "shell")) (run-python (python-shell-calculate-command) nil t)))
I was looking for an easy way to access the Django shell in Emacs. Previously, I used
ansi-term and just ran
./manage.py shell like normal. The big problem with this method was that I didn’t get all of the awesome code-completion and similar features that I would get from the
This elisp function prompts the user to locate their manage.py file. It then temporarily sets the “python shell interpreter” to manage.py and adds “shell” to the argument of manage.py.
run-python is called. It uses
python-shell-calculate-command that basically pieces together the interpreter and args variable we set earlier.
pyvenv-activatecommand for activating virtualenvs.
pip install 'python-language-server[all]'. If you’re using a virtualenv, make sure to install this in your virtualenv as well. Btw, those single quotes are important in that pip install command.