在上一节创建了polls应用
编写polls/views.py
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse("Hello ,This is polls application!")
- 创建polls/urls.py 文件
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$',views.index ,name='index'),
]
- 修改mysite/urls.py,将polls的url路由信息添加进去
from django.conf.urls import url,include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^polls/', include('polls.urls')),
]
- 启动服务
$ python3 manage.py runserver 0.0.0.0:8080