Okay this might be a bad question but as someone who is new to django production I am a little lost
I have deployed my django project on Ubuntu 16.04 with a nginx, gunicorn and postgres stack. I am trying to make some simple template changes in the project (adding content in the .html templates) but the changes aren't showing up when I restart gunicorn and nginx.
All I can find online is reference to the collectstatic command which only seems to collect css, js and img...
How would I go about serving the updated template files?
Thanks in advance for your help.
Related
I created a website that uses vuejs as the frontend and django as the backend with another service running behind everything that im making api calls to.
So django is setup in a way to look at the dist folder of Vuejs and serve it if you run manage.py runserver. but the problem is that my service that I created is
is also in python and it needs to run in a virtualenv in order to work (It uses tensorflow 1.15.2 and this can only run in a contained environment)
I'm sitting here and wondering how I can deploy the django application and keep the virtualenv active and Im coming up with nothing, I've tried doing some research on this but everything I found was not relevant to my problem. I've deployed it and when I close the ssh connection the virtualenv stops.
If there is anyone that can enlighten my ways I would appreciate it.
i think you need to nginx: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04
if you are search for keep states just in terminal i suggest tmux https://github.com/tmux/tmux/wiki
You can use uWSGI and nginx to deploy Django apps on server. Here's helpful articles:
https://www.digitalocean.com/community/tutorials/how-to-set-up-uwsgi-and-nginx-to-serve-python-apps-on-centos-7
https://www.digitalocean.com/community/tutorials/how-to-set-up-uwsgi-and-nginx-to-serve-python-apps-on-centos-7
Django official docs also has a page about it: https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/uwsgi/
There are articles from developers so you can refer them in case you get stuck anywhere:
https://www.freecodecamp.org/news/django-uwsgi-nginx-postgresql-setup-on-aws-ec2-ubuntu16-04-with-python-3-6-6c58698ae9d3/
https://medium.com/#biswashirok/deploying-django-python-3-6-to-digital-ocean-with-uwsgi-nginx-ubuntu-18-04-3f8c2731ade1
I've been reading a lot of blog posts (like this one) on how to deploy Django in a containerized Docker environment.
They all use the runserver command in the docker-compose.yml.
Even the Docker documentation does this.
This suprises me, since using the Django web server is not recommended for production!
What is recommended is pointing the webserver to wsgi.py.
However, none of the articles I've found on Django and Docker explain why they use runserver instead of pointing apache or nginx to wsgi.py.
Why would all these articles use the built-in Django development webserver to handle requests, instead of a full blown webserver like apache or nginx?
Isn't the point of using containers in development, to keep that environment as close to production as possible? Then why build a not-production-ready environment?
The aim of most guides including this you given is to give you a ABC guide to containerize your django applicaiton quickly with docker.
When you decided to read these guides, you are certainly ansumed as experienced django developer, but a new docker user. So the emphasis of these article will not tell you how to use production server(like uwsgi, gunicorn) to manage your django application, because it assumes your are familiar with that.
As a new docker user, it will put more effort to tell you how to dockerize them in container with a start django project. Then, a simple hello-world-like project with development django http server will be the most suitable option.
But, you still need to use uwsgi, gunicorn etc to deploy you apps, E.g. https://hub.docker.com/r/dockerfiles/django-uwsgi-nginx
I'm trying to connect to the server with IP_address_server:8000, but the page load without ever wanting to connect.
In fact, I start a Django project, and I did python3 manage.py runserver 0.0.0.0:8000. In the project settings.py, I've included IP_address_server in ALLOWED_HOSTS (on the server), but I got the same issue.
Could anyone be able to tell me what could be the problem?
First, if you are (really meant to)hosting your django application on cloud, you should not use django's inbuild server, that is manage.py runserver. Check official docs, quoting here:
Now’s a good time to note: don’t use this server in anything resembling a production environment. It’s intended only for use while developing. (We’re in the business of making Web frameworks, not Web servers.)
Now, if I am wrong and your application is indeed hosted on Nginx/apache, check server logs, for Nginx, /var/log/nginx/, for Apache, /var/log/apache2/.
If not, you can follow some of Django deployment guides, eg here or here
I have a regular django site, with djangorestframework (v2.3.14) serving restful api under "/api". On local box everything works fine (mac / mavericks), on remote box (Ubuntu 12) the API browser comes up but all the bootstrap stuff is missing (the page looks like it's out of 1992 prototype instead of pretty bootstrap theme i see locally).
All the pip dependencies have been upgraded and are identical. Locally running site through PyCharm, remotely it is running on WSGI.
What can I check to see what the issue is and resolve it??
I suppose that under PyCharm on your local machine you are running the development server, which serves static files directly from your apps and projects internal locations.
After every deployment into production (your WSGI server) you need to collect all static files to a single place, your STATIC_ROOT. This is a job for the django management command collectstatic, see Django docs here.
The command may look like this:
# Executing collectstatic (organize static files)
python /path/to/your/project/manage.py collectstatic --noinput
For further details you may also read Django cannot find static files. Need a second pair of eyes, I'm going crazy.
If this question doesn't help, you can quicly fix it making a link under your proyect's static folder
ln -s /your_env_folder/lib/pythonX.X/site-packages/rest_framework/static/rest_framework rest_framework
I want to install an existing django app, djangopeople.net. The code is at http://github.com/simonw/djangopeople.net.
I installed django and I understand how to create a new django project.
But how do you deploy an existing app? I know how this works in Rails or Symfony, but I don't really get the django concept here.
Where do I put the files? Which scripts do I run?
Thanks for the steps.
Why is this any different from deploying your own applications? Just put them somewhere in your PYTHONPATH and set up mod_wsgi or whatever to serve them.