我在views.py中创建了一个视图,当我尝试添加URL时出现错误。我正在按照教程进行操作,并且完全按照指示进行。created view
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse("Hello World!")
from first_app import views
urlpatterns = [
url(r'^$',views.index,name='index'),
path('admin/', admin.site.urls),
]
答案 0 :(得分:0)
您需要导入url
,以便可以在urls.py
中使用它
from django.urls import path
from django.conf.urls import url
from first_app import views
urlpatterns = [
url(r'^$',views.index,name='index'),
path('admin/', admin.site.urls),
]
您应该意识到url
是定义网址格式的旧方法,将来可能会弃用