Beyond~

django创建第一个视图

新建项目的根目录里面创建一个view.py文件,然后输入代码

from django.http import HttpResponse

def  hello(request):
    return  HttpResponse("Hello, world.")

接着去urls.py文件里加入以下代码

from django.conf.urls import url
 
from . import view
 
urlpatterns = [
    url(r'^$', view.hello),
]

修改urls.py文件代码

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

from .import view

urlpatterns = [
    url(r'^$', view.hello),
    path('polls/', include('polls.urls')),
    path('admin/', admin.site.urls),
]

 

posted @ 2020-08-05 16:54  燕十三'  阅读(162)  评论(0编辑  收藏  举报