Django Runserver crashes due to autoreload? - django

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.

Related

Jupyter notebook hanging due to Django runserver

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.

Django webserver automatically shuts off on local server when I try to access the admin section

I'm a noob trying to learn Django for the first time, I created a project in a virtualenv on Windows 10. It worked well in the beginning where I was able to login to the admin section after running '''python manage.py runserver'''
But now when I run the same command I'm able to see the Django landing page but as soon as I try to hit http://localhost:8000/admin/ or http://127.0.0.1:8000/admin the server automatically disconnects and I get the "This site can’t be reached" error on Chrome.
I tried changing the port number by running python manage.py runserver 0.0.0.0:8001 but it didn't work. I tried to check if the port (8000) is currently in use by running the cmd (as an admin) netstat -a -b but couldn't find any issues.
The server just quits without any error message
Edit: Currently using Python 3.7.0 and django-3.0.1
There's a ticket about this issue: https://code.djangoproject.com/ticket/31067.
This seems to be a bug in Python 3.7.0, and appears to be fixed in Python 3.7.1. It's still unknown what the exact trigger is for this bug.
Since Django officially only supports the latest patch release of a Python series, this won't be fixed in Django. You can either upgrade your Python version to the latest patch release of 3.7, or downgrade Django to 2.2.
It's a Django 3.0 issue as I've seen. There are so many issues on GitHub, regarding this error.
You may try downgrading to Django 2.* versions for now. Version 2.1/2.2 works fine.

Django Runserver Crashes without Message

I've been working a project for months using Python3 & Django, never had issues regarding starting django but yesterday I formatted my Mac, I have the project in Github so today I clone the project and had bunch of issues with Psycopg2 and Pillow but eventually fixed it.
The problem now is that, when on the terminal I put python manage.py runserver, django simply crashes without any message and I don't know how to find the problem or view any logs regarding the crash, this is all I get:
(backend) ➜ src git:(master) ✗ python manage.py runserver
3Watching for file changes with StatReloader
Performing system checks...
After that it simply crashes and nothing else happens. Any ideas on how to debug this problem? I've tried cloning it again and building it but same results.

Configuring port for django development environment, so the site is available from outside

I am experimenting with django and I throw the code on my server like explained in the first chapters of the django book 2.0.
I have apache running on this server, too (port 80). If I stop apache I can start my django site by calling
sudo python manage.py runserver 0.0.0.0:80
If I access it from another machine by
http://myservername:80
it works fine. Now, apache is running an important page, and I don't want to let apache stoped. How do I make mysite available on another port?
Edit: I'll try to explain more:
When apache runs, typing into the adressfield of my browser, shows me the "important wepage".
Starting my django test project with
sudo python manage.py runserver 0.0.0.0:anotherport
and accessing trying to acces it by
http://ipadressofserver:anotherport
does not work.
If apache is tuned off, and I start my django project by
sudo python manage.py runserver 0.0.0.0:80
I can access it by
http://myservername
http://myservername:80 (the browser changes this to http://myservername/
http://myserverIP and http://myservrIP:80 (The latter resolves in the former).
I am not experienced in Serveradministration so please ask me, if there is something specific I can tell you, to help me solve the problem, please ask me, and I'll provide the information - if possible.
Specify a different port when starting the dev server:
$ python manage.py runserver 0.0.0.0:8000
and connect to the site via:
http://myserverip:8000
You should be able to configure your router appropriately to point to any port. This question should more directly relate to how do you expose a specific port to be browsed. Any information you could provide about your router would be more helpful to address this.

can't get django to work in eclipse + windows

I've installed django on my windows machine, added the pydev and django plugins for eclipse, create a django project, and ran manage.py createapp to create one app. Now when I run manage.py runserver (via eclipse's "custom command" option") It says Validating models... but when I go to http://localhost:8000 I get no response, as though the server is not running. What am I doing wrong?
Try running with --noreload to avoid getting two processes. It helps with error output redirection in eclipse, and may give you more hints towards the actual problem.
Also, do the same from the command-line to see if you get the same problem.
Update: Per Fabio's comment above, you can work around this problem by hacking the code, as explained in this question.