简体   繁体   中英

Django application deployment on Heliohost.org problems

I've got an account at heliohost.org (Johnny Server) and I'm desperately trying to deploy a most simple Django application without any success. It's actually a very simple test application to check everything works fine, but it doesn't.

There are several error logs:

https://pastebin.com/xJBB50dF

And these are the most important files' contents:

.htaccess:

RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(admin_media/.*)$ - [L]
RewriteRule ^(dispatch\.wsgi/.*)$ - [L]
RewriteRule ^(.*)$ /InformeSO/dispatch.wsgi/$1 [QSA,PT,L]

dispatch.wsgi :

import os, sys

# edit your username below
sys.path.append("/home/alber80/public_html")

from django.core.wsgi import get_wsgi_application

os.environ['DJANGO_SETTINGS_MODULE'] = 'InformeSO.settings'

application = get_wsgi_application()

settings.py:

    """
Django settings for InformeSO project.

Generated by 'django-admin startproject' using Django 3.0.8.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os

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


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'nf7w+ajbhz=s_#2y&72&*$v)x#1q2pccrv6t!!*@5l7tx7#$#t'

# SECURITY WARNING: don't run with debug turned on in production!
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',
]

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 = 'InformeSO.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['InformeSO/plantillas'],
        '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 = 'InformeSO.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/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/3.0/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/3.0/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/3.0/howto/static-files/

STATIC_URL = '/static/'

urls.py :

"""InformeSO URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from InformeSO.views import get_informe

urlpatterns = [
    #path('admin/', admin.site.urls),
    #path('informe_sistema/', get_informe)
]

views.py :

from django.http import HttpResponse import datetime from os import system, uname from django.template import Template, Context from django.template.loader import get_template

class Informe(object):

def __init__(self):

    self.so = uname().sysname
    self.version = uname().version
    self.distro = uname().release
    self.arquit = uname().machine

def get_informe(request):

informe = Informe()

doc_externo = get_template('informeso.html')

dicc = {"so": informe.so, "version": informe.version,
        "distro": informe.distro, "arquitectura": informe.arquit}

documento = doc_externo.render(dicc)

return HttpResponse(documento)

And finally, this is the project's directory tree:

InformeSO
├── db.sqlite3
├── InformeSO
│   ├── asgi.py
│   ├── __init__.py
│   ├── plantillas
│   │   └── informeso.html
│   ├── __pycache__
│   │   ├── __init__.cpython-38.pyc
│   │   ├── settings.cpython-38.pyc
│   │   ├── urls.cpython-38.pyc
│   │   ├── views.cpython-38.pyc
│   │   └── wsgi.cpython-38.pyc
│   ├── settings.py
│   └── views.py
└── manage.py

Although I just realised I'm trying to deploy a Python / Django application which references some modules that might not be available on Heliohost.org, because this site doesn't allow shell access, please let me know if you come up with the issue.

Thank you very much in advance.

Try changing ALLOWED_HOSTS = [] to

ALLOWED_HOSTS = ['*']

Thank you for your answer. I already tried that and it gives another error saying that it cannot find the template referred in the code. I have modified the paths in the code and also the directory structure.

I already solved it by specifying the absolute path of the html document, instead of relative path. Thank you very much for your help. :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM