1、根目录下创建mysql.cnf文件
[client]
database = identimg
user = root
password = root
host = 127.0.0.1
port = 3306
default-character-set = utf8 2、修改settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': os.path.join(BASE_DIR,"mysql.cnf"),
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
},
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
} 3、更新pip
//  卸载
pip uninstall pip
// 重新安装
easy_install pip pip -V
// 安装mysql驱动,
pip install mysqlclient 最近装了一次,竟然一直不成功。 555 ~ pip install mysqlclient==1.3.10 这样却是成功的 // 生成数据库表
python manage.py migrate // 创建 polls应用
python manage.py startapp polls
// settings.py 中 添加应用
INSTALLED_APPS = [
'polls.apps.PollsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

// polls下创建urls.py
from django.urls import path
from .SpeakM import test urlpatterns = [
path('speak',test)
]
// 修改项目目录下的urls.py 为
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('api/',include('apiService.urls'))
]
// 创建模型
from django.db import models
// polls/models.py 中
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published') class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0) // 创建数据迁移
python manage.py makemigrations polls // 数据迁移对应的 sql
python manage.py sqlmigrate polls 0001 // 再次数据迁移
python manage.py migrate

总结数据库操作流程

创建管理员账号

python manage.py createsuperuser

// 在 polls/admin.py 中,将Question加入管理

from django.contrib import admin

from .models import Question

admin.site.register(Question)

创建测试

//  将下面的代码写入 polls 应用里的 tests.py 文件内:

import datetime

from django.test import TestCase
from django.utils import timezone from .models import Question class QuestionModelTests(TestCase):

# 测试方法必须test 开头
def test_was_published_recently_with_future_question(self):
"""
was_published_recently() returns False for questions whose pub_date
is in the future.
"""
time = timezone.now() + datetime.timedelta(days=30)
future_question = Question(pub_date=time)
self.assertIs(future_question.was_published_recently(), False)

运行测试

python manage.py test polls

## 结果
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
F
======================================================================
FAIL: test_was_published_recently_with_future_question (polls.tests.QuestionModelTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/path/to/mysite/polls/tests.py", line 16, in test_was_published_recently_with_future_question
self.assertIs(future_question.was_published_recently(), False)
AssertionError: True is not False ----------------------------------------------------------------------
Ran 1 test in 0.001s FAILED (failures=1)
Destroying test database for alias 'default'...

django 简易版搭建的更多相关文章

  1. django框架简介及自定义简易版框架

    web应用与web框架本质 概念 什么是web应用程序呢? Web应用程序就一种可以通过互联网来访问资源的应用程序, 用户可以只需要用一个浏览器而不需要安装其他程序就可以访问自己需要的资源. 应用软件 ...

  2. 简易版CMS后台管理系统开发流程

    目录 简易版CMS后台管理系统开发流程 MVC5+EF6 简易版CMS(非接口) 第一章:新建项目 MVC5+EF6 简易版CMS(非接口) 第二章:建数据模型 MVC5+EF6 简易版CMS(非接口 ...

  3. 学生管理系统(SSM简易版)总结

    之前用 Servlet + JSP 实现了一个简易版的学生管理系统,在学习了 SSM 框架之后,我们来对之前写过的项目重构一下! 技术准备 为了完成这个项目,需要掌握如下技术: Java 基础知识 前 ...

  4. 手动实现一个简易版SpringMvc

    版权声明:本篇博客大部分代码引用于公众号:java团长,我只是在作者基础上稍微修改一些内容,内容仅供学习与参考 前言:目前mvc框架经过大浪淘沙,由最初的struts1到struts2,到目前的主流框 ...

  5. django 简易博客开发 4 comments库使用及ajax支持

    首先还是贴一下源代码地址  https://github.com/goodspeedcheng/sblog 上一篇文章我们介绍了静态文件使用以及如何使用from实现对blog的增删改,这篇将介绍如何给 ...

  6. django 简易博客开发 1 安装、创建、配置、admin使用

    首先贴一下项目地址吧  https://github.com/goodspeedcheng/sblog 到现在位置项目实现的功能有: 1.后台管理使用Admin ,前端显示使用bootstrap 2. ...

  7. 深入理解Mybatis(第一讲)——手写ORM框架(简易版Mybatis)

    我们来自定义一个持久层框架,也就是Mybatis的简易版. 使用端的搭建 idea中新建maven工程IPersistence_test: 在resources目录下新建sqlMapConfig.xm ...

  8. 手写简易版Promise

    实现一个简易版 Promise 在完成符合 Promise/A+ 规范的代码之前,我们可以先来实现一个简易版 Promise,因为在面试中,如果你能实现出一个简易版的 Promise 基本可以过关了. ...

  9. DI 原理解析 并实现一个简易版 DI 容器

    本文基于自身理解进行输出,目的在于交流学习,如有不对,还望各位看官指出. DI DI-Dependency Injection,即"依赖注入":对象之间依赖关系由容器在运行期决定, ...

随机推荐

  1. Scala--reduceLeft

    reduceLeft神语法 val a = Array(20, 12, 6, 15, 2, 9) 1 2 3 4 5 6 7 8 scala> a.reduceLeft(_ + _)  // 数 ...

  2. flutter 常用插件

    audio_recorder: any #录音.播放 flutter_sound: ^1.1.5#录音 dropdown_menu: ^1.1.0#下拉菜单 simple_permissions:#权 ...

  3. Yii1自定义 CGridView 中的操作按钮中 CButtonColumn 选项

    Yii可以使用CButtonColumn自定义按钮及列样式. 效果展示 <?php $this->widget('zii.widgets.grid.CGridView', array( ' ...

  4. 谷歌技术"三宝"之MapReduce

    江湖传说永流传:谷歌技术有"三宝",GFS.MapReduce和大表(BigTable)! 谷歌在03到06年间连续发表了三篇很有影响力的文章,分别是03年SOSP的GFS,04年 ...

  5. Server.Transfer VS Response.Redirect – Simplified

    https://www.codeproject.com/Articles/775221/Server-Transfer-VS-Response-Redirect-Simplified Introduc ...

  6. js 奇偶判断

    function isOdd(num) { == ; } function isEven(num) { == ; } function isSane(num) { return isEven(num) ...

  7. win平台下Path变量消失问题

    解决方法:2019.01.10文章转载自 李北北:https://www.jianshu.com/p/b89f0c99867e 问题描述:修改了path变量,但是环境变量中path消失,于是想再次打开 ...

  8. 20175317 《Java程序设计》第五周学习总结

    20175317 <Java程序设计>第五周学习总结 教材学习内容总结 第五周我学习了教材第六章的内容,了解了接口的知识,学到了以下内容: 明白了什么是接口 学会了如何实现接口 了解了接口 ...

  9. css及HTML知识点

    html : 180°  输出为 css:    margin: 0 auto;会在页面水平居中显示  box-shadow: 0 0 5px #f61818; 设置投影的位置大小颜色 outline ...

  10. 了解FPGA市场现状和未来趋势

    转, 来源: http://www.sohu.com/a/204640373_740053 可编程的“万能芯片” FPGA——现场可编程门阵列,是指一切通过软件手段更改.配置器件内部连接结构和逻辑单元 ...