1,创建项目test04
$ django-admin startproject test04
2,创建应用app为booktest
python manage.py startapp booktest
3,注册应用booktest
作用让创建的应用运行起来
![这里写图片描述](https://img-blog.csdn.net/20170629135219782?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDc0NTE5NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
4,在项目根目录下创建模板templates目录
![这里写图片描述](https://img-blog.csdn.net/20170629135237469?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDc0NTE5NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
- 在项目的settings.py文件中配置模板,如下图:
![这里写图片描述](https://img-blog.csdn.net/20170629135251692?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDc0NTE5NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
5,在项目根目录下创建static目录
![这里写图片描述](https://img-blog.csdn.net/20170629135311384?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDc0NTE5NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
- 在项目的settings.py文件中配置static文件,如下图
![这里写图片描述](https://img-blog.csdn.net/20170629135322315?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDc0NTE5NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
6,数据库的创建与配置
![这里写图片描述](https://img-blog.csdn.net/20170629135337940?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDc0NTE5NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
手动的在mysql数据库中创建test04数据库,如下图
![这里写图片描述](https://img-blog.csdn.net/20170629135423747?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDc0NTE5NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
7,DEBUG开关设置
![这里写图片描述](https://img-blog.csdn.net/20170629135455983?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDc0NTE5NA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
8,设置编码和时间
LANGUAGE_CODE = 'zh-Hans'
TIME_ZONE = 'Asia/Shanghai'
9,项目的urls文件中配置如下:
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^',include('booktest.urls'))
]
10,在booktest应用下创建urls目录并配置
from django.conf.urls import url
from booktest import views
urlpatterns = [
url(r'^success/$', views.success),
url(r'^login_ajax/$', views.login_ajax),
url(r'^login_ajax_check/$', views.login_ajax_check),
url(r'^verify_code/$', views.verify_code),
url(r'^post_article/$', views.post_article),
]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
11,在booktest应用views中创建各个视图函数
from django.shortcuts import render
from django.http import JsonResponse
from PIL import Image, ImageDraw, ImageFont
from django.http import HttpResponse
from django.shortcuts import render, redirect
import random