【django】【my_blog】编写第一个响应

2018-05-07  本文已影响5人  JerichoPH

编写第一个响应

创建文件夹blog/view

from django.http import HttpResponse
from django.shortcuts import render


def index(request):
    return HttpResponse('ok')

设置项目urls.py

from django.conf.urls import url, include
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^blog/', include(arg='blog.url', namespace='blog'))
]

设置应用url.py

from django.conf.urls import url
from django.contrib import admin

from view import article

urlpatterns = [
    url(regex=r'^article/index/$', view=article.index, name='article$index'),
]

查看结果,访问:http://localhost:8000/blog/article/index/

上一篇 下一篇

猜你喜欢

热点阅读