Select your language

Django is a Python-based framework for developing web applications.

We offer you the latest Python versions for your Managed Flex Server. We regularly update these versions.

These instructions describe how to set up and operate a Django application on your Managed Flex Server.

Requirements

To set up and run a Django application, you need at least a Managed Flex Server M.

Building a Django application

This guide explains how to create a simple “Hello World” application that returns a simple text in response to HTTP requests.

We recommend that you create an ~/app/ folder for your applications and then subsequently keep a separate subfolder for all of your applications. This ensures that your applications are organized and easily accessible. We will therefore create the folder ~/app/helloworld for the Django application and move into this folder:

mkdir -p ~/app/helloworld
cd ~/app/helloworld

In the newly created ~/app/helloworld application folder you can now create the required structure for your application. In this example, we are setting up a simple Django project:

python3 -m venv venv
source venv/bin/activate
pip install django gunicorn
django-admin startproject helloworld .

We recommend that you install your Python projects in their own, discrete virtual environments. In this example, this is done using "python3 -m venv venv && source venv/bin/activate".

In this example, a simple text string is returned in response to HTTP requests. To do this, edit the file ~/app/helloworld/helloworld/urls.py as follows:

~/app/helloworld/helloworld/urls.py
from django.contrib import admin 
from django.urls import path 
from django.http import HttpResponse 

urlpatterns = [ 
    path('', lambda r: HttpResponse('Hello World')), 
    path('admin/', admin.site.urls), 
]

In the Django settings, the ALLOWED_HOSTS variable also needs to be modified. For the sake of simplicity, access is allowed from all domains:

sed -i "" "s/ALLOWED_HOSTS =.*/ALLOWED_HOSTS = ['*']/" ~/app/helloworld/helloworld/settings.py

Integration

Using Custom Service Control

The Custom Service Control (CSC) can handle operations and the automatic management of your application, e.g. starting and stopping it when performing maintenance on your server.

It is extremely easy to configure the Django helloworld app in the CSC. To do this, create a new custom service for the Django application.

hpservices supervisord add helloworld

This creates a configuration framework for the new service in the file ~/.services/supervisord/helloworld/service.conf. Only the command needs to be modified for the Django application; all other suggested values can be accepted (remove semicolon at the beginning of the line).

~/.services/supervisord/helloworld/service.conf
[program:django]
command=%(ENV_HOME)s/app/helloworld/venv/bin/gunicorn helloworld.wsgi -b 127.0.0.1:8080 ; the program (can take args)
directory=%(ENV_HOME)s/app/helloworld/       ; directory to cwd to before exec (default no cwd)
autostart=true                ; start application at supervisord start (default: true)
stopwaitsecs=10               ; max num secs to wait before SIGKILL (default 10)
stdout_logfile=%(ENV_HOME)s/.services/supervisord/helloworld/log/default.log
stdout_logfile_maxbytes=1MB   ; filesize at which to rotate logfiles (default ist 50MB)
stdout_logfile_backups=10     ; number of stdout logfile backups (0 means none, default 10)
stderr_logfile=%(ENV_HOME)s/.services/supervisord/helloworld/log/default.err
stderr_logfile_maxbytes=1MB   ; filesize at which to rotate logfiles (default is 50MB)
stderr_logfile_backups=10     ; number of stderr logfile backups (0 means none, default 10)

You can activate the new configuration for your Django application using supervisorctl update:

supervisorctl update
helloworld: added process group

Attention: If you receive an error, you must uniquely execute before "hpservices supervisord start".

For more detailed information on working with CSC and the options it offers, refer to the guide for Custom Service Control.

Web server configuration

If you now want to make your application accessible via HTTP(S), you must configure your website in the Hostpoint Control Panel so that the web server will route requests to your application via proxy.

In your Hostpoint Control Panel, create a website of the type “Nginx proxy for own application”:

Website erstellen Port 8080 en

Server address and port
The proxy function expects your application to be listening on the IPv4 loopback address 127.0.0.1, so you only need to enter the port: 8080.
Please use this form only to provide feedback on the above guide.
For support requests please use this form instead.

 

 

© 2001 - Hostpoint AG
Cookie

Wir verwenden Cookies  🍪

We use Cookies  🍪

Nous utilisons des cookies  🍪

Utilizziamo dei cookie  🍪

Die digitalen Auftritte von Hostpoint (Website, Control Panel, Support Center etc.) verwenden Cookies. Diese werden dazu verwendet, um Daten über Besucherinteraktionen zu sammeln. Wenn Sie auf «Akzeptieren» klicken, stimmen Sie der Verwendung dieser Cookies für Werbezwecke, Website-Analyse und Support zu. Gewisse essenzielle Cookies sind jedoch für eine ordnungsgemässe Funktion dieser Seiten unerlässlich und können deshalb nicht deaktiviert werden. Auch ohne Ihre Zustimmung können gewisse Daten in anonymisierter Form für statistische Zwecke und zur Verbesserung unserer Websites verwendet werden. Bitte beachten Sie unsere Datenschutzerklärung.

Hostpoint's digital presences (website, Control Panel, Support Center, etc.) use cookies. These are used to collect data on visitor interactions. If you click “Accept”, you agree to the use of these cookies for advertising purposes, website analysis and support. However, certain cookies are essential for the proper functioning of these pages and therefore cannot be disabled. Even without your consent, certain data may be used in anonymized form for statistical purposes and to improve our websites. Please note our Privacy policy.

Le sites Web de Hostpoint (site Web, Control Panel, Centre d'assistance, etc.) utilisent des cookies. Ces cookies servent à collecter des données sur les interactions des visiteurs. En cliquant sur «Accepter», vous consentez à l’utilisation de ces cookies à des fins de publicité, d’analyse du site Web et d’assistance. Certains cookies essentiels sont cependant indispensables au bon fonctionnement de notre sites Web et ne peuvent donc pas être désactivés. Même sans votre consentement, certaines données peuvent être utilisées sous forme anonymisée à des fins statistiques et pour améliorer notre sites Web. Veuillez prendre connaissance de notre Déclaration de protection des données.

Le presenze digitali di Hostpoint (sito web, Pannello di controllo, Support Center, ecc.) utilizzano i cookie. Questi vengono utilizzati per raccogliere dati sulle interazioni dei visitatori. Facendo clic su «Accetta», acconsente all’utilizzo di questi cookie per scopi pubblicitari, di analisi del sito web e di supporto. Alcuni cookie essenziali sono tuttavia indispensabili per il corretto funzionamento di questi siti web e pertanto non possono essere disattivati. Anche senza il Suo consenso, determinati dati potrebbero essere utilizzati in forma anonima per fini statistici e per l’ottimizzazione dei nostri siti web. Si prega di tenere conto della nostra Dichiarazione per la pivacy.

Ablehnen
Decline
Refuser
Rifiuta
Akzeptieren
Accept
Accepter
Accetta