django-个人网站之环境配置(一)
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/ 得到以下结果: ? ?至此,我们初步的框架就搭建而成了。 ? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |