创建工程和应用
[root@host-100-100-5-17 ~]# cd ~/ALU[root@host-100-100-5-17 ALU]# django-admin.py startproject alu02[root@host-100-100-5-17 ALU]# cd alu02[root@host-100-100-5-17 alu02]# python manage.py startapp blog
修改alu02/settings.py
...# Application definitionINSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'blog',]...# Database# https://docs.djangoproject.com/en/1.9/ref/settings/#databasesDATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'ALU', 'USER': 'root', 'PASSWORD': 'admin_root', }}...
修改alu02/urls.py
urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^blog/index$', 'blog.views.index'),]
修改blog/views.py
[root@host-100-100-5-17 alu02]# cat blog/views.pyfrom django.shortcuts import renderfrom django.http import HttpResponsedef index(req): return HttpResponse('hello world
')[root@host-100-100-5-17 alu02]#
运行
[root@host-100-100-5-17 alu02]# python manage.py runserver
测试界面