I am trying to add translations for some strings in a django application running under nginx. I run makemessages and that updates the django.po for the specified language, I can see with rosetta that the translations are correct and there are no fuzzy items and I run compilemessages. However when I swtiched to the language I added the translations for, only the previous translations are shown but not the new strings. I also stopped and started nginx but that had no effect.
in the end the problem was that the django code was running in a separate process, using FastCGI, so that a restart of nginx had no effect. Instead I had to restart the FastCGI process with a script I found:
/etc/init.d/django site_name restart
Related
I’ve made a Django third party app, which I’m using in a Django project, running in Docker Compose. I want to translate ValidationError messages from the app inside the project, but the makemessages command doesn’t detect them. I thought, I’ll just add them manually, but when I call makemessages after that, my manually added translations are commented out.
I’ve looked for solutions, and found those SO-posts
Django translations of third party apps
Django's I18N with third-party apps
The posts explain that I should be using symlinks, but I have had no success of doing it (same results as above), see an example below:
docker-compose exec web ln -s /usr/local/lib/python3.8/site-packages/mypackage ./
docker-compose exec web python manage.py makemessages --locale=da --symlinks
So I’m looking for help, what am I doing wrong or could I do something else? Maybe translate the messages inside the third party app itself like Django Rest Framework does?
I hope you can help, very much looking forward for anything that can point me in the right direction.
I have been learning Django in the development mode for a two months and I am up to speed with most basic aspects of python + django now. However, I was using the built-in runserver till this time
Now, I have got a Webfaction hosting account and wanted to know the following
1) Webfaction sets up the project with a certain Django version (say 1.6.4) and Python version (say 2.7) initially
The project directory (for say project MYAPP) is /<>/webapps/MYAPP
When the site is running in production mode, how does the apache server know which Python version, and which site-packages versions to use with the MYAPP source code to render the site?
I can see that the MYAPP folder has a lib/python2.7 folder, however when I am connected to SSH terminal, and do a "which python", i see :
which python
/usr/local/bin/python
so, do I take that this is the Python executable that is being used for rendering the website instead of the one in webapps/MYSITE/lib/python2.7 folder? How does the information/data flow about which programs to use during rendering the site with apache mod_wsgi work?
2) I was using a virtualenv in the development mode during testing. How do I use this on webfaction in production mode?
3) I am using Pycharm IDE. It worked well for the development mode. I can see that it has a remote interpreter configuration and a Deployment setting/option.
The python path that the remote interpreter settings tool detects automatically is the python executable at /usr/local/bin/python
Is this fine, or should I be pointing it to the more local python2.7 in the webapps/lib folder?
Thanks a lot of the answers and pls let me know if you need any supplemental info
Note to the OP: This should really be three separate questions.
1) For WebFaction, your Django app will use the Python version (and libraries, etc.) defined in:
~/webapps/<appname>/apache2/conf/httpd.conf
Specifically, you'll want to look at what is defined for WSGIPythonPath (which should mostly match up with WSGIDaemonProcess unless you modify the config and are doing something strange).
Note that which python just tells you what the default python is in your shell. This has nothing to do with the config file for the webapp.
2) You may want to expand on this as to exactly what your use case is and why the default Django webapp created by WebFaction doesn't fit your needs. But the short answer is:
Create a virtualenv on your WebFaction account.
Install Django, etc. into the virtualenv.
Edit the httpd.conf file I mentioned above to use your virtualenv instead.
I've done this with both a Django webapp made via the WebFaction control panel and via a custom mod_wsgi webapp. So it does work. Just make sure to use the right Python version when making your virtualenv.
3) I don't use PyCharm so I can't answer this (one reason why this question should be split up).
I'm using Django 1.4.1 with the gunicorn and nginx on my server with a setup similar to Django-Nginx-Gunicorn.
What I need is a good place to hook into Django, so that I can initialize stuff like signal listeners on startup (so it works with all management commands and server startup).
I am aware that a lot of people use urls.py or the middleware hack (Where to put Django startup code?), but those don't seem to get called when I run python manage.py shell. And at some point down the road a startup signal will be available, but I don't want to fork Django to include it, unless absolutely necessary.
I really like the startup script technique from Entry Point Hook Django Projects and it works correctly when using python manage.py runserver or any other management command. However, gunicorn starts Django without calling the management command and I can't figure out where I would modify my gunicorn startup script to run the startup.py, as shown in the WSGI.py example. Any solutions?
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
I have an install of django on apache using embedded wsgi. I DON'T have root on the machine.
How can I tell apache to reload the python instance when I deploy new source code?
I tried removing all the .pyc files and it still is running the old code.
If you are running mod_wsgi in daemon mode with apache, you may not have to restart apache to get it to reload.
I just touch my wsgi file (unix: touch updates the 'saved date' of a file) and apache reloads it on next access/web-hit.
See http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide
... as long as you can alter the timestamp on the WSGI script.
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
This article about reloading source code with mod_wsgi goes into how to reload source code, and even how to create a monitor script to automatically reload the daemon when you make source changes. It's really good for setting up a development environment using mod_wsgi.