Django-hosting » History » Revision 29
Revision 28 (Nico Schottelius, 11/05/2020 05:30 PM) → Revision 29/30 (Nico Schottelius, 09/03/2024 02:24 PM)
h1. Django hosting by ungleich {{toc}} h2. Status This document is **IN PRODUCTION** (since 2016-04-08). Pricing can be found on the "ungleich products page":https://ungleich.ch/u/products/django-hosting/. h2. Version 1: VM Based (obsolete as of 2023) h3. How to use # Configure your app # Deploy your app # Install project specific python requirements into the pyvenv # Restart uwsgi to restart your app # Go to http://your-hostname/ and enjoy! h3. h2. Configure your app h4. h3. WSGI * Ensure that there is _projectname_/wsgi.py in your project root h5. h3. Database Add the following to your settings.py: <pre> DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'app', } } </pre> h4. h3. Static and media files Static files should be placed in */home/app/app/static* and media files in */home/app/app/media*. Use the following code for configuration: <pre> PROJECT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) STATIC_ROOT = os.path.join(BASE_DIR, "static/") MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media') </pre> Usually to generate/deploy the static files, you can use collectstatic: <pre> python manage.py collectstatic </pre> h3. h2. Deploy (first time) You can login to your VM as user *app*: <pre> ssh app@MYHOSTNAME git clone <path-to-your-project> ~/app </pre> * Deploy / update your app into the folder *~app/app* (that is the app folder in the home of the user app) * We recommended to use git to deploy it h3. h2. Deploy (update) <pre> ssh app@MYHOSTNAME cd ~/app git pull </pre> h3. h2. Install python requirements into the pyvenv Pyvenv has been installed to *~app/pyvenv* for you. Required packages for the hosting like PostgreSQL support and uwsgi support have already been placed. You need to use pyvenv found in *~app/pyvenv*, as uwsgi loads this pyvenv before loading your app. To install your requirements use: <pre> . ~/pyvenv/bin/activate pip install ... </pre> h3. h2. Restarting the app * *sudo systemctl restart uwsgi* h4. h3. Viewing logfiles * nginx access log: *tail -F /var/log/nginx/access.log* * nginx error log: *tail -F /var/log/nginx/error.log* * uwsgi log: *tail -F /var/log/uwsgi/app/app.log* h3. h2. Description of the stack h4. h3. Technologies * Debian * nginx * PostgreSQL * uwsgi * python3 venv h4. h3. Configuration * user "app" ** in group "adm" (to view logfiles) * PostgreSQL with ** database "app" ** Listens only on localhost / socket (no remote connections)