如何在托管服务上部署Django应用程序

2024-04-18 05:00:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我不熟悉网络开发。我从Siteground购买了网络托管启动包来托管我的图形设计组合网站。这是一个简单的Django应用程序,它是一个单页的公文包,带有一个联系人表单,使用Django的sendmail through gmail服务。在

我从未部署过Django应用程序,更不用说我自己的网站了。我只制作和部署了一个Wordpress网站,这是非常不言自明的。在

我知道如何通过FTP将我的网站上传到服务器,但我不知道如何配置Django应用程序以进行部署(除了他们文档中的简要说明),也不知道如何将应用程序连接到我的服务器以在域上运行。在

我想我应该在wsgi中配置一些东西,但我不太明白它是如何工作的,我也找不到任何地方支持在Siteground(或类似的东西)上部署Django应用程序,尽管他们支持python。在

我连接了Sitegrounds的SSH来学习Django部署的一些教程,但是即使是Linux,我也不能使用(或者不知道如何)sudo apt get来遵循这些教程。在

这是我的设置.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)'

我知道我必须将'Debug=True'改为'Debug=False',在'Allowed\'Hosts'中插入我的域的IP,并将我的目录指向服务器的目录(public\u html),但我只知道这些。在

有谁能告诉我正确的方向来理解如何在Siteground上部署python应用程序?或者至少给我一个资源来解释python应用程序在服务器托管服务上的部署?在

有可能保留sqlite还是必须学习mysql(哪个Siteground支持)?在

编辑:以下是Sitegrounds关于非Wordpress或Joomla网站的部署信息(他们几乎没有任何信息)。在

  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.

关于部署的唯一其他信息是特定于Wordpress或其他PHP框架的。在


Tags: thetodjangoauthtrue应用程序youros
1条回答
网友
1楼 · 发布于 2024-04-18 05:00:19

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?

几周前,我刚刚在CentOS上部署了一个Django应用程序。SSH告诉我您将使用某种类型的虚拟机,因此这些教程应该非常适合您:

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

我用过这些。我们用的是和数字海洋一号一样的堆栈。在

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

您可以继续使用SQLite。我不确定它需要什么额外的配置。在

相关问题 更多 >