Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
7 contributors

Users who have contributed to this file

@luto @SalocinHB @The-Compiler @jammon @927589452 @Finn0811 @copykatze
199 lines (122 sloc) 3.82 KB
.. author:: Finn <mail@f1nn.eu>
.. tag:: lang-python
.. tag:: web
.. tag:: audience-developers

About

Django

.. tag_list::

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.


Note

For this guide you should be familiar with the basic concepts of

License

All relevant legal information can be found here

Prerequisites

Your URL needs to be setup:

[isabell@stardust ~]$ uberspace web domain list
isabell.uber.space
[isabell@stardust ~]$

Installation

Step 1

Step 2

Install django

[isabell@stardust ~]$ pip3.6 install django --user
[isabell@stardust ~]$

Create a django project. We will use "MyDjangoProject" during this guide.

[isabell@stardust ~]$ django-admin startproject MyDjangoProject
[isabell@stardust ~]$

Migrate database

[isabell@stardust ~]$ python3.6 ~/MyDjangoProject/manage.py migrate
[isabell@stardust ~]$

Configuration

Configure Hostname

Edit ~/MyDjangoProject/MyDjangoProject/settings.py and edit the line ALLOWED_HOSTS = [] to add your host name.

ALLOWED_HOSTS = ['isabell.uber.space']

If you need to add multiple host names, separate them with commas like this:

ALLOWED_HOSTS = ['isabell.uber.space', 'www.isabell.example']

MySQL

It is recommended to run Django with a database other than the default SQLite once you go into production. Additionally, the SQLite version provided by the underlying CentOS 7 is too old for Django >=2.2. The following step changes the database engine to the better performing MySQL.

Open ~/MyDjangoProject/MyDjangoProject/settings.py and edit the database block to look like this

DATABASES = {
  'default': {
      'ENGINE': 'django.db.backends.mysql',
          'NAME': 'DB_NAME',
      'USER': 'DB_USER',
      'PASSWORD': 'DB_PASSWORD',
      'HOST': 'localhost',
  }
}

Configure web server

Note

Django is running on port 8000.

Setup daemon

To deploy your application with uwsgi, create a file at ~/uwsgi/apps-enabled/myDjangoProject.ini with the following content:

Warning

Replace <username> with your username! (4 times)

Test installation

Perform a CURL request to djangos port to see if your installation succeeded:

[isabell@stardust ~]$ curl -I localhost:8000
HTTP/1.1 200 OK
Content-Type: text/html
X-Frame-Options: SAMEORIGIN
Content-Length: 16348
[isabell@stardust ~]$

If you don't see HTTP/1.1 200 OK check your installation.

Finishing installation

Point your browser to URL and create a user account.

Best practices

Security

Change all default passwords. Look at folder permissions. Don't get hacked!


Tested with Django 2.0.5, Uberspace 7.1.6

.. author_list::
You can’t perform that action at this time.