Django+python服务器部署与环境部署教程详解

作者:Britain_King 时间:2023-01-29 15:16:22 

需要准备环境:python3.6、vultr(或者其他服务器)、xshell

第一步:python安装必备环境Django库

Xshell链接远程主机:

Django+python服务器部署与环境部署教程详解

点击连接之后:弹窗输入访问用户及密码,一般为root用户

Django+python服务器部署与环境部署教程详解
Django+python服务器部署与环境部署教程详解

成功连接到目标服务器:

[root@vultr ~]#

安装python以及需要环境(此为安装完python3.6环境),运行pip安装即可:

pip install django

提示Success安装成功

第二步:项目创建

首先cd到自己想要新建项目的路径:
我这里选择的是在data下新建文件夹pytest来保存项目


cd /data
mkdir pytest
cd pytest

接下来进行新建项目 django-admin startproject +(你的项目名:此处使用的是pytest)


django-admin startproject pytest
cd pytest #进入项目
cd pytest #进入项目配置列表

此时项目的状态是


[root@vultr pytest]# tree
.
├── db.sqlite3
├── manage.py
└── pytest
├── asgi.py
├── __init__.py
├── __pycache__
│ ├── __init__.cpython-36.pyc
│ ├── settings.cpython-36.pyc
│ ├── urls.cpython-36.pyc
│ └── wsgi.cpython-36.pyc
├── settings.py
├── urls.py
└── wsgi.py

接下来重要的一步在setting.py中设置访问权限:
划重点——这个地方是可以访问的外部主机地址,为了方便访问我们改为['*'],意思为任何主机都可访问


# 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',
"settings.py" 120L, 3093C

修改完成后(确保开放8000端口的访问,防火墙中设置):

python manage.py runserver 0.0.0.0:8000

成功开启:


[root@vultr pytest]# python manage.py runserver 0.0.0.0:8000
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.

March 28, 2020 - 02:27:55
Django version 3.0.4, using settings 'pytest.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.

然后访问浏览器输入服务器ip+端口号例如:22.21.21.200:8000

Django+python服务器部署与环境部署教程详解

之后可以在服务器端查看日志:

[28/Mar/2020 02:28:42] "GET / HTTP/1.1" 200 16299

来源:https://blog.csdn.net/dbldwang/article/details/105156110

标签:django,python,部署
0
投稿

猜你喜欢

  • python生成n个元素的全组合方法

    2023-11-10 20:35:08
  • Python设计模式中的结构型适配器模式

    2023-07-19 11:59:54
  • PyCharm2019.3永久激活破解详细图文教程,亲测可用(不定期更新)

    2022-04-27 23:51:16
  • python如何通过psutil获取服务器cpu、内存、磁盘使用率

    2022-11-07 01:01:29
  • 解决python3 urllib中urlopen报错的问题

    2022-01-11 10:33:32
  • Centos 6.4源码安装mysql-5.6.28.tar.gz教程

    2024-01-25 09:39:58
  • python实现图片压缩代码实例

    2023-07-11 06:35:22
  • TypeScript中泛型的使用详细讲解

    2024-04-17 10:35:23
  • Playwright快速上手指南(入门教程)

    2022-09-25 02:44:23
  • python实现12306登录并保存cookie的方法示例

    2021-08-05 18:37:55
  • 如何远程使用服务器上的Jupyter notebook

    2023-02-08 10:45:54
  • python里将list中元素依次向前移动一位

    2021-03-23 16:53:43
  • 深入理解Django的中间件middleware

    2023-05-11 18:29:46
  • Django修改app名称和数据表迁移方案实现

    2022-12-14 17:09:11
  • vueJs函数toRaw markRaw使用对比详解

    2024-04-09 10:46:23
  • Python类的动态修改的实例方法

    2021-07-03 12:16:15
  • Go语言map字典用法实例分析

    2024-04-26 17:29:18
  • go语言制作的zip压缩程序

    2024-02-12 21:03:00
  • 获取python的list中含有重复值的index方法

    2022-03-06 20:54:02
  • python基础教程之基本数据类型和变量声明介绍

    2023-08-28 22:45:55
  • asp之家 网络编程 m.aspxhome.com