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

编写第一个响应

创建文件夹blog/view

  • 并创建__init__.py文件和article.py
  • 修改article.py文件:
from django.http import HttpResponse
from django.shortcuts import render


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

设置项目urls.py

  • 修改my_blog/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

  • 创建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/

推荐阅读更多精彩内容