Jupyter notebook hanging due to Django runserver - django

Some time ago I made a simple Django application. Recently, I started using Jupyter notebooks for Python and was wondering if I could run my application from such a notebook. To test that, I opened a new notebook and navigated to the top directory of the application:
%cd d:\adressen
To see if the application could be run from the notebook, I first tried:
!py manage.py makemigrations
It returned, as it should:
No changes detected
So far so good. Now starting the server:
!py manage.py runserver
In a sense nothing happend. No output, the cell label still showing as In[*]. Nevertheless, the server was running, for if I opened in my webbrowser the page http:\\localhost:8000, my application turned up and all features were working.
I fail to see why in the notebook makemigrations is handled correctly and runserver makes it hanging. The Jupyter console did not show anything that could have gone wrong.
Having looked at some other questions and answers about Jupyter and Django, I installed django-extensions and included it in the installed apps. That did not help. When I start Jupyter with python manage.py shell_plus --notebook, open a new notebook and use the same commands, the same happens.
Any suggestions on why this happens and how to overcome it are highly appreciated.

At last I think I found what is going on here and how to overcome it.
With the Jupyter shell command !py manage.py runserver Django indeed starts the server, but also wants to write to a console. There is no console, so Jupyter seems to hang.
When instead we use !start py manage.py runserver, not only Django starts the server, but also a console opens in which we see the standard Django output when opening a server.
In this way I can use a Jupyter notebook as an IDE for Django projects.

Related

How do i run two command lines in AWS simultaneously?

I have a Django app that I am trying to deploy to AWS.
I need two command lines to run the app. One command line will be used to runserver and another one to run a background task. That is how the app runs in my localserver.
How do I start two command lines in AWS?
As i can understand your django app is currently in development mode, I've used tmux for development mode, this page will guide you better to use tmux. Once you have started a tmux session run python3 manage.py runserver and then detach to the session using ctrl-b then press d and now your app will run even after you exit the shell.
To know more about tmux go through this page.
In case you have to run your app in production mode Don't use above method, run your app with any of nginx or apache2 server. This tutorial can guide you to set up your django app with nginx and gunicorn.
Supervisor is a good way to control that. You can run a lot of processes (like server, migration, collectstatic, Celery) easily.
Additionally, you can ensure that all processes will run again when your machine reboots.
And, as everybody said, you have to install a server in production that supports WSGI in order to run Django properly.

Django Runserver crashes due to autoreload?

so i'm very new to Django. But my problem is as follows:
When I create a project, the runserver often won't start. I type:
python manage.py runserver
Powershell freezes for a while and says: "Python is not responding"
The Problem does not appear when typing:
python manage.py runserver --noreload
I am using Windows 10 and Django 1.10.6 as well as Python 3.6
The problem has also been reported on the forum of djangoproject but there was no solution offered. Is there any way to fix this?
Will disableling autoreload affect working with the Localhost?
Thank you.
I just started encountering this same bug tonight. I'm not sure how to fix it just yet or what causes it, but running with --noreload won't hurt anything. The server just won't reload when you make a Python change, so you'll have to restart the server yourself to test changes.

Python 2.7 not working -- refusing to serve hidden directly , via 404 Error

CMD error message
jupyter 404 error message
I was able to work fine with python (jupyter notebook) until yesterday, and I turned off the command prompt that was running python. When I try to restart python by typing in jupyter notebook in cmd, it throws a 404 error. I think the possible reason for this is that I was running python as a server and connecting it to asp.net website in visual studio with IIS running the asp.net. So the python server on port 8888 might still be running, and I think that is what's preventing me from opening jupyter notebook.
So I tried the following steps to get it to work, but it throws the same error:
Pressed ctrl+c twice to interrupt the kernel (interuppted but still did not run jupyter notebook afterwards)
Uninstalled Python 2.7 Anaconda and reinstalled
Removed IIS website and tried running python by itself (still not worked)
My question comes down to this:
How do I get the jupyter notebook to run? Should I try closing the port 8888 and running jupyter notebook again?
In case someone faces the same issue, I am posting an answer to my question :)
Answer:
Open Anaconda prompt then type in "jupyter notebook"

Heroku app with Django and postgres crashing unexpectdly

I am new to Django development, but I am in a situation where I need to deploy a large project on Heroku.
I ran my app in local system, it worked fine.
I pushed the same to Heroku and it also worked fine. But after few hours I open my app URL in browser , then app is saying Some thing has broken,intimated to admin.
The app worked fine before few hours, but what happened after few hours.
I just pushed my old DB backup to Heroku DB, Thats it app running fine now.
But I confused what happened to my app, I am facing this problem again and again,
how can I avoid this problem in future.
My app configuration:
psycopg2==2.4.5
Django==1.4
This could be a number of causes. It sounds more like a database issue. I would run the following command
heroku pg # TAKE NOTE OF THE HEROKU_POSTGRESQL_[COLOR]_URL
heroku pg:reset HEROKU_POSTGRESQL_[COLOR]_URL --confirm [appname]
This will reset your postgres database that is the active one, remove all tables etc.
Then I would run the regular command to get your database backup and running.
manage.py syncdb
You can also do the following
manage.py validate
This will go through your modules and tell you if any errors are present.
If that fails - enable debug in your settings.py file.
Also you can run "heroku logs" this will tell you the last few errors and statuses that have been hit with your app.
Let me know if this works, if not I will help debug further.

IPython Kernel Non-Responsive: Running a Django development server from an IPython Notebook

I'm trying to run this line of code in an IPython Notebook:
!manage.py runserver
It executes manage.py runserver on the command line and then starts the Django development server at http://127.0.0.1:8000/ and allows me to debug / develop my Django project.
The problem is that when I execute this in the notebook the notebook hangs because the Django server is constantly reloading / does not pass control back.
Is there any way to pass an interrupt like Control+C to the command line or gain control over the IPython kernel so that I can continue along with my project in the notebook?
I opened up an issue on IPython dev's github. Minrk found this solution:
import subprocess
server = subprocess.Popen(["python", "manage.py", "runserver"])
it allows me to view the dev server and continue to develop it in the IPython Notebook. sweet!