python安装django找不到set.up_<一> 环境安装、配置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、

48aea7116f1da18737859f9804d023c3.png

2、

b1e44fba64e39cd399a12346df229242.png

3、

66e2b5724ae93e33c076f01485ecc1ed.png

4、

1f4dbf472779a5c26cd8dd7e6f94529b.png

5、

cef1fc8d0d463b665d2caf9f7147858e.png

6、

cc2ccdd6061515d60a79417bbf7f2ac8.png

7、

b50fffa985e08796ce66bf7b34986b1b.png

安装vagrant

版本:vagrant_2.1.0_x86_64

1、

cd6529cf5f22eb9125c5aadd6b30e886.png

2、

615d70a3f9a149d30f81f5394c8ff332.png

3、

2666b83e80c57e71ab96d2d561c4d64b.png

4、

2a980b9663e5bb709ad9fc636243ddb5.png

5、重启下电脑

ce45db0130ead4936624e9ad44b7a179.png

6、验证

bc1ef77c397e5ff2f0ee80f846da00b2.png

配置启动虚拟机

在F盘新建devops 文件夹,将centos-7.2.box 拷贝到F:\devops 中

1、打开cmd

a29650697d39a527425000bab0382bea.png

2、初始化

F:\devops>vagrant init centos-7.2.box

3d3463ca3a0083a3aacf1c5d393aaf66.png

会在F:\devops中生产配置文件Vagrantfile,修改端口转发,访问主机的8000端口会调到虚拟机的8000端口

config.vm.network "forwarded_port", guest: 8000, host: 8000

3、启动:启动过程可能比较长,耐心等待

F:\devops>vagrant up

b39f22dfcb056f190c81c086baa263c1.png

自动挂载

048ecd89acd3b2e43faad72a21ee1bcf.png

4、更改配置文件Vagrantfile启动端口

config.vm.network "forwarded_port", guest: 8000, host: 8000

报错如下:

ad333a412fac643bb9286aeddfa5bf0a.png

解决:安装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

19d046d5e54a05e0687cf6418ae8345c.png

0b5ae93d28c119b4bcbfc4fb4c1237a0.png

8f8f6630fc993fe65d1ffcc61cc7dbb6.png

实现了共享目录

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

8cb516469090e4e4d946a54e0d484514.png

c551814a9a1024413d435721e9dadde4.png

虚拟机安装环境

1、[root@localhost 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 <

[global]

index-url = http://pypi.douban.com/simple

trusted-host = pypi.douban.com

[list]

format=columns

EOF

[root@localhost 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、新建虚拟环境

用普通用户创建

安装:

[vagrant@localhost ~]$ sudo /usr/local/python36/bin/pip3 install virtualenv

创建:

[vagrant@localhost ~]$ /usr/local/python36/bin/virtualenv ./python36env

进入:

[vagrant@localhost ~]$ source ./python36env/bin/activate

(python36env) [vagrant@localhost ~]$ pip list

Package Version

pip 18.1

setuptools 40.4.3

wheel 0.32.1

安装django

(python36env) [vagrant@localhost ~]$ pip install "django>=1.11,<2.0"

安装数据库:

(python36env) [vagrant@localhost ~]$ 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) [vagrant@localhost ~]$ sudo systemctl start mariadb

(python36env) [vagrant@localhost ~]$ sudo systemctl enable mariadb

安装数据库模块:

(python36env) [vagrant@localhost ~]$ pip install mysqlclient

mysql初始化:

(python36env) [vagrant@localhost ~]$ mysql_secure_installation

(python36env) [vagrant@localhost ~]$ 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) [vagrant@localhost ~]$ 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) [vagrant@localhost ~]$ cd /vagrant/

(python36env) [vagrant@localhost vagrant]$ django-admin startproject devops

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

314a41dcddd643c2416145ca8bca4ced.png

pycharm设置:

1、在pycharm中打开F:\devops

2、添加:

585facc523441c7b1acab55c5bdd4c23.png

3、设置关联linux

当前目录必须和Vagrantfile同一个目录才行

f25c88c68537c98033cdf8baef5763a9.png

af97a898a37bf2a6c901db13ebe05055.png

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、验证:

8ba40576f8b4b4d7ab22f06dc0b889a7.png

创建app

1、将python3加入到环境变量中

(python36env) [vagrant@localhost ~]$ 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) [vagrant@localhost ~]$ source .bash_profile

3、(python36env) [vagrant@localhost ~]$ cd /vagrant/devops/

4、(python36env) [vagrant@localhost devops]$ python manage.py startapp dashboard

5、设置urls路径:

5c2057d524f150f32979ac7a5812c4d1.png

6、添加app

cad31b63c5fb885dea6111e385d57942.png

7、

a6b2e5a954c21218f16ed7788a47b708.png

验证:

ac3cfe932dfe1b8ec43f196a00da3a82.png

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

57c20957cee6bedaf486e481c081076c.png

练习个登录操作

get:获取

post:提交

delete:删除

1、安装模块

pip install requests

2、编写url

0994daeb663b1b500e98062281eb35de.png

3、编写view

a6744655f2cb09052ccb11b09999fe89.png

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

0294e7fbf8d52999f5ce026cb7604e94.png

3、验证:

5f7dafb7cedfff4e9813192988060ec6.png

同步数据库

1、使用django命令行工具同步数据库

python manage.py makemigrations

python manage.py migrate

python manage.py showmigrations

4a934650031c2206abad87eae72602fc.png

487cd01cd84bd65e1f2f191208d05070.png

创建用户

1、创建普通用户

44e63f4335ac6dff4e7ad024883cb148.png

2、查看数据库

145ea60dd0e1d4b8b1ca4c56eaf646ec.png

3、创建管理员用户

3b6f659da54e9fefb2c8a7326850e315.png

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

e7601ed24f185dd84d31a28694bc1b24.png

5、修改密码

d5de1d2b30015fd0a2d49a95d80d9dbb.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Traceback (most recent call last): File "D:\PyCharm Community Edition 2022.3.3\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode coro = func() File "<input>", line 1, in <module> File "D:\PyCharm Community Edition 2022.3.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "D:\PythonProject\Django_dianshang\utils\loaddata.py", line 2, in <module> from goods.models import * File "D:\PyCharm Community Edition 2022.3.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "D:\PythonProject\Django_dianshang\goods\models.py", line 7, in <module> class Category(models.Model): File "D:\anaconda3\envs\djangopro\lib\site-packages\django\db\models\base.py", line 129, in __new__ app_config = apps.get_containing_app_config(module) File "D:\anaconda3\envs\djangopro\lib\site-packages\django\apps\registry.py", line 260, in get_containing_app_config self.check_apps_ready() File "D:\anaconda3\envs\djangopro\lib\site-packages\django\apps\registry.py", line 137, in check_apps_ready settings.INSTALLED_APPS File "D:\anaconda3\envs\djangopro\lib\site-packages\django\conf\__init__.py", line 102, in __getattr__ self._setup(name) File "D:\anaconda3\envs\djangopro\lib\site-packages\django\conf\__init__.py", line 82, in _setup raise ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
05-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值