I have a project deployed on production with gunicorn and nginx (may be info about environment will help to answer on my question). While building some new functionality i want to see full errors traceback. In settings.py i switched debug=True also i have specified ALLOWED_HOSTS=['host.com','ip_adress'] but this mode isn't work. I expect that when i open 404 page i should see traceback.
I know that enabling debug to true on production isn't a good way. But i need it.
You need to restart your gunicorn socket after making such changes:
sudo systemctl restart yourgunicornsocket
Related
I'm working on a Django webapp that's running under nginx and uWSGI. When I deploy new Django code (e.g., settings.py), do I need to restart uWSGI? If so, why?
Background: I had a scenario where I updated settings.py and some other code and deployed it. I did not see the changes in the webapp behavior until I restarted uWSGI.
Yes, you need to restart the uWSGI process.
Python keeps the compiled code in memory so it won't get re-read until the process restarts. The django development server (manage.py runserver) actively monitors files for changes, but that won't happen by default with other servers. If you want to enable automatic reloading in uWSGI, the touch-reload and py-auto-reload uWSGI arguments might help.
After changing the view function without runserver again, and press F5 to refresh the page, Django will not reload the new view but use the previous one. but if you change the template, Django always uses the new one.
So, Is there a way to make Django reload the view every time the user refresh the page, I think that is very convenient for develop to modify the view function frequently.
If you are running django using the dev server (./manage.py runserver) then it will always reload when it detects any code changes. This is even more efficient than reloading with every request. If you make a change, it reloads when it needs to.
If you are running a production server (nginx, apache, etc) and you want code-reload, then you need to add something to your wsgi module to detect code changes.
Code reloading with apache: http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
Code reloading with uwsgi: http://projects.unbit.it/uwsgi/wiki/TipsAndTricks
It is a known issue with PyDev. I would suggest running the server from terminal/cmd.
cd to your project directory where manage.py is present and run the server using
python manage.py runserver
You don't need to run the project from eclipse menu.
Any changes made in eclipse would be reflected as soon as they are made.
If you are running Django as a WSGI application in daemon mode you just need to touch the wsgi.py for your site and it will reload the application next time there is a request. (So no need for any special options).
I noticed it is a setting in pyDev run configurations. I wonder why but it seems --noreload is configured by default. So I edit arguments of run settings and now the server is reloading also when editing views.
Try using gunicorn or nginx as running server... They dont restart on code change
try typing
gunicorn --bind 0.0.0.0:8080 app.wsgi:application
Hi everyone i'm trying to learn the django framework and I'm using PyDev (Eclipse Python Development Framework/Plugin). When I try to run my application I get an error:
Error: [Errno 10013]
I know that this is because of the port. I use the port 8000 and i want to change it to 8080. Does anyone knows what exactly should i do to change the port?
pydev debugger: starting
Validating models...
0 errors found
Django version 1.3.1, using settings 'muapp.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Error: [Errno 10013]
It might be useful to point out that PyDev, like Eclipse, runs the configured command when the Run button is pressed. How is the default command and/or its options changed?
Have a look at this video tutorial. Skip about 14 minutes in. Then use runserver 8080 instead of runserver in the arguments.
Please take a look at the PyDev Documentation on how to change the Run configuration.
Run/Debug as Django
Run as Django/Debug as Django are available (note that they set the
--noreload by default).
This will create a default Run configuration, so, you may edit it
later through run > run configurations (or debug > debug
configurations) if you want to change a parameter.
Note: to know how to rerun the last launch see: the Rerun Last Launch
topic on PyDev Launching
Note 2: if the --noreload is not passed, only the parent process will
be killed from Eclipse and the others will only be killed when they'd
be reloaded (i.e.: on a code-change).
Whether it's "Eclipse" or "PyDev", right-click on the Project and select "Run As" --> "Run Configurations..."
Additionally, according to the django Documentation,
runserver [addrport]ΒΆ
Starts a lightweight development Web server on the local machine. By
default, the server runs on port 8000 on the IP address 127.0.0.1. You
can pass in an IP address and port number explicitly.
Therefore, in your Project's Run Configuration, on the Arguments tab, simply add:
runserver 0.0.0.0:8080
This should have the server listen on all interfaces/IPs. Alternatively, you can make it more specific to your public-facing IP instead:
runserver 123.456.789.123:45678
Please, note that in this case, my IP would be "123.456.789.123" and the port would be "45678".
The following Answers might also be of use:
How to make Django's devserver public ? Is it generaly possible?
How can i get the running server URL
External Link; Third-party blog-post
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.
We have django 1.1.1 website, that works fine on development server (python manage.py runserver). But when we use nginx + wsgi, ngnix is timed out and return "504 Gateway is time out". error.log is empty.
So, probably it is environment issue but I don't know where to start because it was working fine and now its not and I have no error to point me in the right direction. Restarting nginx doesn`t help.
I'm new enough to this environment, could someone possible give me some idea of how I could find the problem
Thanks,
Derek
You can try setting DEBUG = True in settings.py and see if you can review the errors.
If that doesn't work, set DEBUG back to False try setting up the ADMINS so you receive emails with the error reports.
Those are my only suggestions at the moment. Good luck.
Look at the error logs for the Nginx server. My guess is that it's invoking something through FCGI or WSGI (whatever you had set up), but that it's not responding correctly. More detail should be in those logs.
It turned out to be mistake in the middleware configuration ... fixed it and all back to normal.