防止伪造数据添加数据库,关闭方式
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
python manage.py startapp front
import pymysql
pymysql.install_as_MySQLdb()
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'book_manage',
'USER': 'root',
'PASSWORD': 'kouhz',
'HOSTNAME': '127.0.0.1',
'PORT': '3306'
}
}
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'front',
]
from django.urls import path
from front import views
urlpatterns = [
path('', views.index),
path('add_book/', views.add_book, name='add_book'),
path('book_detail/', views.book_detail, name='book_detail'),
]
from django.shortcuts import render, redirect, reverse
from django.db import connection
##操作数据库需要corsor和db connection
def get_cursor():
return connection.cursor()
def index(request):
cursor = get_cursor()
cursor.execute("select id,name,author from book")
books = cursor.fetchall()
return render(request, 'index.html', context={"books":books})
def add_book(request):
pass
def book_detail(request, book_id):
pass
Title
{% load static %}
Title
/* *代表所有标签
外边距位0
内边距0
不适用浏览器提供的默认样式
*/
*{
margin: 0;
padding: 0;
}
/*背景颜色 高度 默认每一个显示一行,使用overflow让显示内容浮动*/
.nav{
background: #3a3a3a;
heigth: 65px;
overflow: hidden;
}
/*nva 里面的 li 标签左浮动,list-style :去掉点*/
/*margin:上下0 左右20*/
/*字体放在中间,设置行高,和外面的nav一样高*/
.nav li{
float: left;
list-style: none;
margin: 0 20px;
line-height: 65px;
}
/*nav 的 li 标签 的 a 设置为白色,取消下划线*/
.nav li a{
color:#fff;
text-decoration: none;
}
/*鼠标放置在a上面的颜色*/
.nav li a:hover{
color:pink;
}