image-identify

1, 安装mysql

    1. sudo apt-get install mysql-server
      查看版本:mysql -V
    1. 登录  mysql -u root -p
    1. 创建用户
        mysql> CREATE USER ‘test’@‘localhost’ IDENTIFIED BY ‘1234’;

这样就创建了一个名为:test 密码为:1234 的用户。

注意:此处的"localhost",是指该用户只能在本地登录,不能在另外一台机器上远程登录。如果想远程登录的话,将"localhost"改为"%",表示在任何一台电脑上都可以登录。也可以指定某台机器可以远程登录。

    1. 创建数据库
      CREATE DATABASE 数据库名
  • 5.为用户添加权限参考
      mysql>grant all privileges on testDB.* to test@localhost identified by ‘1234’;
     mysql>flush privileges;//刷新系统权限表
     格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by “密码”;

2. django安装和mysql驱动库

参考

    1. 安装pip
$ wget https://bootstrap.pypa.io/get-pip.py
$ python get-pip.py
$ pip -V  #查看pip版本
    1. 安装MySQL驱动 : pip install mysqlclient
      报错:
      Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-install-0ai4qtgr/mysqlclient/
      解决: mysql没有安装完全
      sudo apt-get -y install mysql-server sudo apt-get -y install mysql-client sudo apt-get -y install libmysqlclient-dev

原文

    1. 安装django :pip install django==1.11.4
      查看django版本:python -m django --version
      或者
      sudo apt install python-setuptools
      easy_install django
      查看版本:
python
>>>import django
>>>django.get_version()

django 创建项目

  • 1, django-admin 创建项目
django-admin startproject imgany

创建完后我们看工程目录结构
▾ imgany/ |~
pycache/ |~
init.py |~
settings.py |~
urls.py |~
view.py |~
wsgi.py |~

  • 2, 启动服务,0.0.0.0:8000表示可以让外界访问,服务在8000端口
python manage.py runserver 0.0.0.0:8000

报错如下

    from bs4 import BeautifulSoup
ImportError: No module named 'bs4'

应该是代码里的bs4库没有安装
将涉及到的库都装上

   pip install requests  (发起网络请求)
   pip install beautifulsoup4   (网页解析)
   pip install Pillow   (图像库)

同时我们将数据库映射表创建,避免后面运行报错.

数据库映射:            
 python manage.py migrate  #创建表结构
 python manage.py makemigrations analy
 python manage.py migrate analy  

这时候我们再看mysql的数据库表格,django已经自动替我们完成了

mysql> use imgany
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------------------+
| Tables_in_imgany           |
+----------------------------+
| analy_img                  |
| analy_test                 |
| auth_group                 |
| auth_group_permissions     |
| auth_permission            |
| auth_user                  |
| auth_user_groups           |
| auth_user_user_permissions |
| django_admin_log           |
| django_content_type        |
| django_migrations          |
| django_session             |
+----------------------------+
12 rows in set (0.00 sec)

运行服务

在浏览器中输入
http://127.0.0.1:8000/hello
可以看到正常hello world就说明服务已经成功搭建了.

猜你喜欢

转载自blog.csdn.net/u014742281/article/details/88354269