第三方
- 本次课程中主要介绍一些常用的第三方Django模块,包括
布署
- 当项目开发完成后,需要将代码放到服务器上,这个过程称为布署
- 服务器上需要有一个运行代码的环境,这个环境一般使用uWSGI+Nginx
创建示例项目
- 在~/Desktop/pytest目录下,进入工作环境py_django
cd ~/Desktop/pytest
workon py_django

django-admin startproject test6

cd test6
python manage.py startapp booktest

- 在test6/settings.py中INSTALLED_APPS项安装应用

- 在test6/settings.py中DATABASES项配置使用MySQL数据库test2,数据库在第二部分已经创建

- 在test6/settings.py中TEMPLATES项配置模板查找路径


- 打开test6/urls.py文件,包含booktest的url配置

- 在booktest/目录下创建urls.py,配置url
from django.conf.urls import url
from . import views
urlpatterns=[
url(r'^$',views.index),
]
- 打开booktest/views.py文件,定义视图index
#coding=utf-8
from django.shortcuts import render
def index(request):
return render(request,'booktest/index.html')
- 在templates/booktest目录下创建文件index.html,代码如下
<html>
<head>
<title>第三方包</title>
</head>
<body>
<h1>第三方包</h1>
</body>
</html>
python manage.py runserver
