DATABASES = {
‘default’: {
# ‘ENGINE’: ‘django.db.backends.sqlite3’,
# ‘NAME’: os.path.join(BASE_DIR, ‘db.sqlite3’),
# ‘ENGINE’: ‘C:\ProgramData\MySQL\MySQL Server 5.7\Data\db1’,
‘ENGINE’: ‘django.db.backends.mysql’,
‘NAME’: ‘book_manage’,
# ‘NAME’: ‘db1’,
‘USER’: ‘root’,
‘PASSWORD’: ‘kevin202’,
‘HOST’: ‘localhost’,
‘PORT’: ‘3306’
}
}
base_1.html
{% load static %}
index_1.html继承base_1.html
{% extends ‘base_1.html’ %}
{% block content %}
{% for book in books %}
{% endfor %}
序号 | 书名 | 作者 |
---|---|---|
{{ forloop.counter }} | {{ book.1 }} | {{ book.2 }} |
{% endblock %}
static ‘front/base_1.css’
base_1.css
*{
margin: 0;
padding: 0:
}
.nav{
background: #3a3a3a;
height:65px;
overflow: hidden;
}
.nav li{
float: left;
list-style: none;
margin: 0 20px;
line-height: 65px;
}
.nav li a{
color: #fff;
text-decoration:non;
}
.nav li a:hover{
color: lightblue;
}
urls.py
path(‘index_1/’,views.index_1,name=‘index_1’),
views.py
def index_1(request):
cursor = get_corsor()
cursor.execute(‘select id,name,author from book’)
books_1 = cursor.fetchall()
# for i in books_1:
# print(i)
return render(request,‘index_1.html’,context={“books_1:”:books_1})
效果
127.0.0.1:8080/index_1/