Django: How to restart webserver so that changes in sourcecode get applied - python

I using Eclipse with PyDev to develop Django Webapplication. I can start my webserver with
python manage.py runserver
and then I can test my webapplication locally in my browser. However everytime I change the sourcecode I have to restart eclipse so that these changes get applied in my webapplication.
I guess I have to somehow restart the webserver so that my sourceode gets interpreted again so that my changes get applied. But how do I do that? I couldnt find any command to do so.

Django dev server restarts it self when python code changes. This may not happed if you run it with noreload option
./manage.py runserver --noreload
Another case when the server is not reloaded automatically is when the files changes is not used by django. For example if you have syntax error in your admin.py django won't use it. And changing it won't restart the server.
Have in mind that if you use eclipse debug you will have to run django with noreload because of an bug that does not relaunch the instance but starts a new one.

First, configure the project as a django project in eclipse, if not already so. (Right click on the project, and select PyDev -> Set as Django Project).
Second, click on the green run button at the top, and select "run configurations". Select the PyDev Django icon and hit the new launch configuration button at the top. Enter the project name, (let's say testproject), and "${workspace_loc:testproject}/${DJANGO_MANAGE_LOCATION}" for the main module.
On the Arugments tab, enter "runserver 0.0.0.0:8000 --noreload" if you want to your server to be visible for machines outside yours, or "runserver --noreload" if you want access on your machine only, and change the working directory to "${workspace_loc:}".
Click apply and you should be set to go!
Here's what it should look like when running inside of eclipse:

Related

entering manage.py runserver in the shell, the Django server opens Texteditor instead of starting the server

When I type manage.py runserver in the shell, there only opens my text editor, instead of starting the server. I do not understand this issue. The documentation of django says, the server should start.
to start the server u should type python manage.py runserver and
before this make sure that you are in the correct dir and also make sure you are working within your created environment.
Solution was to go in windows default settings and change the program to open .py files to python

Development server is not starting and getting no response

I am a beginner for django web development. Initially i created a project and an app. When i try to run the django server using the python manage.py runserver command it loads for sometime and i get no response.
I am using Pycharm 2019 community edition
You mention you are using PyCharm. Can you use your terminal window within PyCharm (normally at the bottom, possible toggle view with Alt+F12). In that terminal window try typing python manage.py runserver and see if that gives you an error.

How to hide the console when running the django developement server?

I want to run the django developement server localy and I don't want to use a full webserver.
So far I renamed manage.py to manage.pyw. Then in manage.pyw I call execute_from_command_line(['manage.py', 'runserver'])
In a batch file I then use "START pythonw manage.pyw"
The problem is, that I then cannot connect to the server even though in the taskmanager it says it's still running. When I start it using python instead, it runs, but the console window is visible.
I found a way to do this. I used the Windows Service Wrapper https://github.com/kohsuke/winsw to install python manage.py runserver as a service.

Django - Could not find source to reload

I'm currently using LiClipe with PyDev to debug my project.
I have a separate module which sits in the core directory of my Django project.
While the project is running in Debug mode I'm able to edit code, save it and then get a confirmation that it is working in the console.
However when I edit this particular module I get the following issue which I'm not sure how to approach:
pydev debugger: Start reloading module: "pspotter" ...
pydev debugger: Could not find source to reload (mod: pspotter)
pydev debugger: reload finished
Furthermore the code doesn't seem to be running as it's using apscheduler.
Am I meant to reference this file from somewhere else?
In the latest version, when you're running under the debugger, PyDev will try to make a reload on the existing process. In this particular case it can't find the module to reload in sys.modules and it's just warning you that the reload failed (so, it's just signalling that you have to restart the debug session in order to get those changes as it wasn't able to do a 'hot' reload).
If you don't want to use that feature, you can disable it in the preferences > pydev > debug > 'when file is changed automatically reload'.

Django in Pydev spawns multiple processes?

I have my project setup in PyDev in Eclipse. Whenever I debug my project, things go great, but once I try to restart the Django server, it spawns an additional runserver process, blocking up the port I'm using for the server (8000). Is there a workaround to make sure it really kills the server?
Django reloads the server each time changes are made to any Python code (running another instance of the server and killing the old one). It seems that it's not handled properly when launched from Pydev. You can deactivate this by adding the --noreload argument to the server starting command.
More information: --noreload, pydev/django (look for the remark below Run/Debug as Django)

Categories