环境安装、配置django

环境安装

以下的环境版本
1、vagrant_2.1.5_x86_64.msi
2、VirtualBox-5.1.0-108711-Win.exe
3、centos-7.2.box

安装VirtualBox
版本:VirtualBox-5.1.0-108711-Win

1、

2、

3、

4、

5、

6、

7、

安装vagrant
版本:vagrant_2.1.0_x86_64

1、

2、

3、

4、

5、重启下电脑

6、验证

配置启动虚拟机
在F盘新建devops 文件夹,将centos-7.2.box 拷贝到F:\devops 中
1、打开cmd

2、初始化
F:\devops>vagrant init centos-7.2.box

会在F:\devops中生产配置文件Vagrantfile,修改端口转发,访问主机的8000端口会调到虚拟机的8000端口
config.vm.network "forwarded_port", guest: 8000, host: 8000

3、启动:启动过程可能比较长,耐心等待
F:\devops>vagrant up

自动挂载

4、更改配置文件Vagrantfile启动端口
config.vm.network "forwarded_port", guest: 8000, host: 8000

报错如下:

解决:安装Windows6.1-KB2506143-x64.msu Windows6.1-KB2819745-x64-MultiPkg.msu

6、再次运行vagrant up

7、可以不用打开VirtualBox ,直接通过xshell连接虚拟机

可以通过key连接,key在F:\devops.vagrant\machines\default\virtualbox,导入这个key


实现了共享目录

虚拟机的镜像文件存在以下位置

虚拟机安装环境

1、[[email protected] tools]# wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz
2、yum install net-tools *sz openssl-devel readline-devel unzip vim -y
3、tar xf Python-3.6.6.tgz
4、cd Python-3.6.6
5、./configure --prefix=/usr/local/python36
6、make && make install
7、导入pip源
tee /etc/pip.conf <<EOF
[global]
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
[list]
format=columns
EOF

[[email protected] Python-3.6.6]# vi /etc/pip.conf

[global]
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
[list]
format=columns

8、新建虚拟环境
用普通用户创建
安装:
[[email protected] ~]$ sudo /usr/local/python36/bin/pip3 install virtualenv

创建:
[[email protected] ~]$ /usr/local/python36/bin/virtualenv ./python36env

进入:
[[email protected] ~]$ source ./python36env/bin/activate

(python36env) [[email protected] ~]$ pip list
Package Version



pip 18.1
setuptools 40.4.3
wheel 0.32.1

安装django
(python36env) [[email protected] ~]$ pip install "django>=1.11,<2.0"

安装数据库:
(python36env) [[email protected] ~]$ sudo yum -y install mariadb mariadb-server mariadb-devel

编辑:
vi /etc/my.ini
mysqld的模块中
default-storage-engine = innodb
innodb_file_per_table
collation-server = utf8_general_ci
init-connect = ‘SET NAMES utf8’
character-set-server = utf8

启动:
(python36env) [[email protected] ~]$ sudo systemctl start mariadb
(python36env) [[email protected] ~]$ sudo systemctl enable mariadb

安装数据库模块:
(python36env) [[email protected] ~]$ pip install mysqlclient

mysql初始化:
(python36env) [[email protected] ~]$ mysql_secure_installation

(python36env) [[email protected] ~]$ mysql_secure_installation


NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we‘ll need the current
password for the root user.  If you‘ve just installed MariaDB, and
you haven‘t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password: 123456
Re-enter new password: 123456
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from ‘localhost‘.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named ‘test‘ that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you‘ve completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

创建数据库:

(python36env) [[email protected] ~]$ mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> create database devops CHARACTER SET utf8;
Query OK, 1 row affected (0.01 sec)

创建django项目:
(python36env) [[email protected] ~]$ cd /vagrant/
(python36env) [[email protected] vagrant]$ django-admin startproject devops

在vagrant中创建是因为这个目录关联到了window目录,这样可以在windows上开发

pycharm设置:
1、在pycharm中打开F:\devops
2、添加:

3、设置关联linux
当前目录必须和Vagrantfile同一个目录才行

4、设置数据库:
在settings中设置:

DATABASES = {
    ‘default‘: {
        ‘ENGINE‘: ‘django.db.backends.mysql‘,
        ‘NAME‘: ‘devops‘,
        ‘USER‘: ‘root‘,
        ‘PASSWORD‘: ‘123456‘,
        ‘HOST‘: ‘127.0.0.1‘,
        ‘PORT‘: 3306,
        ‘OPTIONS‘:{
            ‘init_command‘: ‘SET default_storage_engine=INNODB;‘,
        },
    }
}

5、验证:

创建app

1、将python3加入到环境变量中
(python36env) [[email protected] ~]$ vi .bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin:/home/vagrant/python36env/bin

export PATH

2、(python36env) [[email protected] ~]$ source .bash_profile

3、(python36env) [[email protected] ~]$ cd /vagrant/devops/

4、(python36env) [[email protected] devops]$ python manage.py startapp dashboard

5、设置urls路径:

6、添加app

7、

验证:

数据格式为字典或者列表:

练习个登录操作
get:获取
post:提交
delete:删除

1、安装模块
pip install requests

2、编写url

3、编写view

4、在settings.py中禁用csrf功能

3、验证:

同步数据库
1、使用django命令行工具同步数据库
python manage.py makemigrations
python manage.py migrate
python manage.py showmigrations

创建用户
1、创建普通用户

2、查看数据库

3、创建管理员用户

4、查看,1表示管理员,0表示普通用户

5、修改密码

原文地址:http://blog.51cto.com/jacksoner/2300450

时间: 2024-10-13 22:50:37

环境安装、配置django的相关文章

安装配置Django

安装配置Django 以下是基于python3.5 pip install Django 把python环境目录Scripts配置到环境变量,主要在命令行中随时可以使用django-admin 验证 如下证明安装成功: 创建项目 cd workspace\Py\Django django-admin startproject mysite,低版本的python需要django-admin.py startproject mysite 启动

SVN Server环境安装配置手册

SVN Server环境安装配置手册_百度文库 http://wenku.baidu.com/link?url=923bv1olSkznh1gWd7Gqoxxwj18IHIlTXcEbNiPSLM5H32k93UtQ22rAVppNIlVv89ru4E1cPFe1yESSEkSsR4NfDMMRgpA2d3GI_KcV37m

[转载]SharePoint 2013测试环境安装配置指南

软件版本 Windows Server 2012 标准版 SQL Server 2012 标准版 SharePoint Server 2013 企业版 Office Web Apps 2013 备注:安装之前,需要各个服务器的IP地址,机器名称设置好,并且已经加入到域中. 一 安装AD域控制器 1. 添加AD服务 a) 打开服务器管理器,选择[添加角色和功能] b) 在[开始之前]页面直接点击[下一步] c) 选择[基于角色或基于功能的安装]后,点击[下一步] d) 选择[从服务器池中选择服务器

第四篇(1):企业常用Linux web环境安装配置(apache、php、mysql)

上篇我们讲了基本的软件包管理和文件操作什么的,现在也要动手安装点有用的东西了吧! 本篇我会写出一个用yum安装apache.php.mysql的方法,最后再运行phpMyAdmin来管理数据库. 1.如何在Linux主机上安装apache 由于之前我们安装了完成的centos系统,所以可能系统有可能已经安装好了apache,所以我们先检查下是不是真的安装过了 先敲命令吧,yum list installed httpd* ,如果看到httpd已经安装,那么就yum -y remove httpd

XMPP-04环境安装(配置客户端)

四.配置客户端 1.来到XMPP官网,寻找所需客户端软件 2.选用电脑自带的信息,Adium和Spark这三个客户端软件,我共享的资源里有 3.首先来配置信息 打开信息 ->添加账户 ->其他邮件账户 ->继续 ->账户类型:Jabber ->用户名:zhangsan ->密码:123456 ->创建 XMPP-04环境安装(配置客户端),布布扣,bubuko.com

storm0.9.1 集群环境安装配置

Storm安装配置 三台机器  131,132,133 需要安装 jdk,python,autoconf-2.64,zeromq-3.2.2,jzmq 安装jdk和python不详细说. 1  安装 autoconf-2.64, 1.1 下载 http://download.chinaunix.net/download.php?id=29328&ResourceID=648 上传到lunix上的工作目录 比如  /home/bigdata/ 解压  tar -xvf   autoconf-2.6

J2EE环境安装配置

在下载,安装前先说下下面几个概念JDK,SDK,JRE,JVM ◆JDK Java Develop Kit (Java 开发包) ◆SDK Software Develop kit, 以前JDK叫做Java software develop kit,后来出了1.2版本后就改名叫JDK了,省时省力, 节约成本. ◆JRE Java runtime environment 我们的最简单的HelloWorld程序必须在JRE(Java运行环境,Java运行环境又叫Java平台)才能跑起来.显然JRE其

fedora gtk+ 2.0环境安装配置

1.安装gtk yum install gtk2 gtk2-devel gtk2-devel-docs 2.测试是否安装成功 pkg-config --cflags --libs gtk+-2.0 执行此命令,看看能否把相应的路径和库显示出来,如果可以,说明安装成功 3.写个小测试程序 4.编译 敲入make命令进行编译,编译后运行就可以看见窗体显示在屏幕上 fedora gtk+ 2.0环境安装配置

【Mac + Appium + Java1.8学习(三)】之IOS自动化环境安装配置以及简单测试用例编写(模拟器、真机)

前提条件: =========================================== 1.Xcode版本为Xcode10及以上2.Appium版本必须为1.9及以上,因为Xcode为10.0 3.appium-desktop4.安装所需依赖库,包括: a.Homebrew b.Git c.node (brew install node) d.npm (brew install npm)e.carthage (brew install carthage)f.libimobiledev

Jmeter环境安装配置

Jmeter环境安装配置 Apache下的开源免费 java开发 运行环境jre jdk 跨平台 jre  java运行环境的英文缩写 jdk   java开发工具包的英文缩写(包含了jre) java  -version 安装jre建议 1.8 下载免费的jmeter 启动jmeter 原文地址:https://www.cnblogs.com/htx18/p/12150450.html