How to deploy django app on hosting service

Question:

I’m new to web development. I bought the web hosting start-up package from Siteground to host my graphic design portfolio website. It’s a simple Django app that is a one-page portfolio with a contact form using Django’s sendEmail through gmail service.

I’ve never deployed a Django app, let alone my own website. I’ve only made and deployed a WordPress website which is pretty self-explanatory.

I understand how to upload my website to the server through FTP, but I have no idea how to configure the Django app for deployment (aside the brief explanation in their docs) or how to connect the app to my server to run on the domain.

I think I’m supposed to configure something in wsgi, but I don’t really understand how that works and I can’t find support anywhere on deploying a Django app on Siteground (or something like it) even though they have python support.

I connected to Sitegrounds’ SSH to follow some tutorials on Django deployment, but even though it’s Linux I can’t use (or don’t understand how to) sudo apt-get to follow the tutorials.

Here is my settings.py:

import os

with open('cfsite/key.txt') as f:
    SECRET_KEY = f.read().strip()

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Debug Settings
DEBUG = True

ALLOWED_HOSTS = ['']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'crispy_forms',
    'cfapp',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'cfsite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'cfsite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = '/home/iamcrys8/public_html/static'

# Crispy Forms settings

CRISPY_TEMPLATE_PACK = 'bootstrap4'


# Email Backend settings

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_SSL = True
EMAIL_PORT = 465
EMAIL_HOST_USER = '(email go here)'
EMAIL_HOST_PASSWORD = '(email pass go here)'

I know I have to change ‘Debug=True’ to ‘Debug=False’ and insert my domains’ IP in the ‘Allowed_Hosts’ as well as pointing my directories to the servers’ directory (public_html), but that’s all I know.

Can anyone please point me in the right direction to understanding how to deploy python apps on Siteground? Or at least point me to a resource that explains the deployment of python apps on server hosting services?

Is it possible to keep sqlite or do I have to learn mysql (which Siteground has support for)?

Edit: Here is Sitegrounds’ deployment information regarding non-Wordpress or Joomla websites (which they have barely any information on).

  1. Move your files: First, you will need to move your website files from your previous host to SiteGround by using FTP (File Transfer
    Protocol).
  2. Move your database: Then, you will have to move your database. Start with exporting the database from your previous hosting account.
    If you’re not sure how to do this, contact the support of your
    previous host to get more info. When you get your data exported,
    create a new database on your new SiteGround hosting account and
    import your content into it.
  3. Reconfigure your application: The last step of transferring your site is to reconfigure your application to work from the new place. In
    WordPress, that’s the wp-config.php file, while in Joomla it is
    configuration.php. Replace the values with your actual database,
    database username and password for it. Save this file and your site
    should be up and running from your new SiteGround hosting account. The
    configuration steps for every application are different.

The only other info regarding deployment is specific to WordPress or other PHP frameworks.

Asked By: Ethan Thompson

||

Answers:

Can anyone please point me in the right direction to understanding how
to deploy python apps on Siteground? Or at least point me to a
resource that explains the deployment of python apps on server hosting
services?

I just deployed a Django app to production on CentOS a few weeks ago. SSH tells me that you would be using a virtual machine of some sort, so these tutorials should be perfect for you:

https://www.vultr.com/docs/how-to-install-django-on-centos-7

https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-centos-7

I used these. We were using the same stack as the DigitalOcean one.

Is it possible to keep sqlite or do I have to learn mysql (which
Siteground has support for)?

You can continue to use SQLite. I am not sure what additional configuration it would require.

Answered By: Matthew Gaiser

They actually have a Python interpreter installed, but just supply the standard packages. It’s not possible to install new ones via pip. Compare https://www.siteground.com/kb/see-available-python-modules/

I also asked their support.

Answered By: scipper15