1.建立django项目
django-admin startproject myblog
2.进入myblog目录 建立app存储自己的基本信息
python manage.py startapp person
3.在settings.py中注册app,在INSTALLED_APPS里面加入'pseron'
4.在settings.py中设置时间为中国时间:TIME_ZONE = 'Asia/Shanghai'
5.在settings.py中设置templates的路径:在TEMPLATES中设置'DIRS': [os.path.join(BASE_DIR,'templates')],并在项目下新建一个templates文件夹
6.在settings.py中设置静态文件static的路径:加入STATICFILES_DIRS=[os.path.join(BASE_DIR,'static'),],并在项目下新建一个static文件夹
7.在settings.py中设置连接MysqL数据库:配置DATABASES为:
DATABASES = { 'default': { ENGINE': django.db.backends.MysqL,NAMEdjangoUSER':rootPASSWORD123456HOSTlocalhostPORT':3306import pyMysqL pyMysqL.install_as_MysqLdb()
8.在person目录下新建urls.py
9.总体目录为下:
10.整体流程的检测。
(1)myblog/urls.py
from django.contrib admin from django.urls path,include urlpatterns = [ path(admin/'',include(person.urls',namespace=person)) ]
(2)person/urls.py
path from . views app_name= urlpatterns=[ path(person/index) ]
(3)views.py
from django.shortcuts render # Create your views here. def index(request): return render(request,person/index.html')
(4)在templates下新建person文件夹,建立index.html
{% load staticfiles %} <!DOCTYPE html> <html lang="en"> <head> <Meta charset=UTF-8"> <title>Title</title> <link rel=stylesheet" href={% static person/css/index.css'%}> </head> <body> <h1 class=test">hello world</h1> </body> </html>
(5)在static下新建person文件夹,新建css文件夹,建立index.css
.test{
color: aqua;
}
11.启动服务器
python manage.py runserver
出现以下界面,则配置基本没有错。
12.在浏览器输入
http://127.0.0.1:8000/person/
得到以下结果:
至此,我们初步的框架就搭建而成了。