1.django-admin startproject helloword 创建项目helloword

2.开始一个app,写一个hello world
python manage.py startapp hello

4.settings db

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # 你的数据库引擎
'HOST': "localhost", # 你的数据地址,localhost代表本地
"PORT": 3306, # 端口, 数据库的默认端口一般是3306
"USER": "root", # 用户名
"PASSWORD": "", # 密码
"NAME": "study" # 库名
}
} # CACHES = {
# "default":{
# "BACKEND":"django_redis.cache.RedisCache",
# "LOCATION":"redis://127.0.0.1:6379/",
# "OPTIONS":{
# "CLIENT_CLASS":"django_redis.client.DefaultClient"
# }
# }
# }

4.view

import json
from django.shortcuts import render, redirect, reverse
from django.http import HttpResponse
from django.contrib.auth import authenticate, login, logout
from django.contrib import messages # 错误提示信息
from django.views.decorators.csrf import csrf_exempt
from io import BytesIO
from django.views import View
from django.forms.utils import ErrorDict
from django.core.cache import cache
from show.models import Book
# Create your views here.
class CacheVisit(View):
"""
访问数据库缓存
from django.core.cache import cache
"""
def get(self, request):
books = Book.objects.all()
return render(request, '1.html', locals())

5. 1.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
{% for book in books %}
{{ book.title }}&nbsp;&nbsp;&nbsp;
{{ book.author }}&nbsp;&nbsp;&nbsp;
{{ book.download_text }}&nbsp;&nbsp;&nbsp;
{{ book.new }}<br>
{% endfor %}
</body>
</html>

6.url路由

from django.conf.urls import url
from django.contrib import admin
from show import views as view urlpatterns =(
url(r'^admin/', admin.site.urls),
url(r'^show/',view.CacheVisit.as_view()),
)

start django project的更多相关文章

  1. [Python] Create a Django project in Pycharm

    From: http://blog.csdn.net/u013088062/article/details/50158239 From: http://blog.csdn.net/u013088062 ...

  2. Start Your Django Project in Nginx with uWsgi

    Step 0:Install A,B,C,blabla needed This can be seen in my another article in the blog.click here(una ...

  3. Apache:To Config The Vhost of Django Project

    It is not a good idea to use dev server in Production Environment. Apache or Nginx are good choice.B ...

  4. Django project troubleshootings

    1. 当django project文件夹放到cgi-bin目录下面时会出现下面的错误: [Wed Jan 09 01:52:52.611690 2019] [core:notice] [pid 15 ...

  5. django project 的快速构建

    2003年,堪萨斯(Kansas)州 Lawrence 城中的一个 网络开发小组 ——World Online 小组,为了方便制作维护当地的几个新闻站点(一般要求几天或者几小时内被建立),Adrian ...

  6. Prepare tasks for django project deployment.md

    As we know, there are some boring tasks while deploy Django project, like create db, do migrations a ...

  7. 18 12 30 新建一个 django project

    1. 新建一个 django project 1 2 django-admin.py startproject project_name 特别是在 windows 上,如果报错,尝试用 django- ...

  8. Django project structure: how does static folder, STATIC_URL, STATIC_ROOT work

    So I've been messing up with Django(1.6+) project setting for quite sometime, this is what i finally ...

  9. [Django] Start a new django project

    Assume we already have a env created call 'demo-env': cd demo-env . bin/activate pip install django ...

  10. My First Django Project (3) - Apache set up

    Holy moly!!!!因为漏了一下斜杠,害我反复调试了2,3天,无法读取static 文件,一直找不出原因,后来在apache的error.log中发现了原因. 1. 下载了apache 2.4, ...

随机推荐

  1. SPA中使用jwt

    什么是jwt? JSON Web Token (JWT),它是目前最流行的跨域身份验证解决方案 JWT的工作原理 1. 是在服务器身份验证之后,将生成一个JSON对象并将其发送回用户,示例如下:{&q ...

  2. ubuntu修改密码

    ubuntu修改密码 本文链接:https://blog.csdn.net/heybob/article/details/9095727 修改root密码: 1,$sudo su,输入密码进入root ...

  3. 立体像对空间前方交会-共线方程求解法(python实现)

    一.原理 二.步骤 a.用各自像片的角元素计算出左右像片的旋转矩阵R1和R2. b.有同名像点列出共线方程. c.将方程写为未知数的线性方程形式,计算线性系数. d.写出误差方程,系数矩阵与常数项. ...

  4. Spring Cloud Alibaba学习笔记(13) - Spring Cloud Stream的监控与异常处理

    Spring Cloud Stream监控 Spring Boot Actuator组件用于暴露监控端点,很多监控工具都需要依赖该组件的监控端点实现监控.而项目集成了Stream及Actuator后也 ...

  5. echarts字体适配

    var html = document.getElementsByTagName("html")[0]; var width = html.clientWidth; var too ...

  6. Linux基础命令汇总109条

    1       文件管理 1.1     basename 1.1.1     功能说明 从文件名中去掉路径和扩展名 例:basename include/stdio.h .h Output &quo ...

  7. py-1 语言介绍

    一.编程与编程语言 1.编程的目的 计算机的发明,是为了用机器取代并解放人力.而编程的目的则是将人类的思想流程按照某种能够被计算机识别的表达方式传递给计算机,从而达到让计算机能够像人脑.电脑一样自动执 ...

  8. Pycharm 社区版本Database Navigator 安装教程

    虽然Pycharm有专业版和社区版这两个版本,但是在大多数情况下我们都会选择社区版进行下载安装.为啥呢?因为社区版免费呗,而且能够基本满足我们的日常需求(这也就意味着社区版会比专业版少一些功能).针对 ...

  9. Python函数Day4

    一.内容补充 __iter__() 就是 iter(),iter() 调用的就是__iter__() __next__() 就是 next(),next()调用的就是__next__() __clos ...

  10. Python基础——__name__变量

    转自:https://blog.csdn.net/u011511601/article/details/53504355 Python使用缩进对齐组织代码的执行,所有没有缩进的代码,都会在载入时自动执 ...