vscode anacondapython中的未定义变量URL

时间:2019-12-30 02:57:10

标签: python django visual-studio-code anaconda

我在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!")

adding url

from first_app import views

urlpatterns = [
    url(r'^$',views.index,name='index'),
    path('admin/', admin.site.urls),
]

tutorial im following

1 个答案:

答案 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是定义网址格式的旧方法,将来可能会弃用