我是一名新的Python/Django用户(同时也是SO的新手):
在尝试迁移我的Django项目时,出现了错误:
RemovedInDjango110Warning: Support for string view arguments to url() is deprecated
and will be removed in Django 1.10 (got main.views.home). Pass the callable instead.
url(r'^$', 'main.views.home')
显然第二个参数不能再是一个字符串。我是通过 pluralsight.com 上的一篇教程来创建这段代码的,该教程教授如何在先前版本中使用 Django(我目前正在使用1.9)。老师指导我们从应用程序中创建的视图中在urls.py中创建urlpatterns。他教我们创建以下urlpattern:
from django.conf.urls import url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', 'main.views.home')
]
引用
def home(request):
return render(request, "main/home.html",
{'message': 'You\'ve met with a terrible fate, haven\'t you?'}) #this message calls HTML, not shown, not important for question
在我创建的应用程序“main”的views.py中。如果此方法被弃用,那么我该如何将视图参数传递而不是作为字符串?如果我只是删除引号(如文档所示https://docs.djangoproject.com/en/1.9/topics/http/urls/),我会收到一个错误:
NameError: name 'main' is not defined
我尝试使用文档中提供的代码“导入”视图或主要内容:
from . import views
或者
from . import main
这给了我:
ImportError: cannot import name 'views'
并且
ImportError: cannot import name 'main'
我相信我已经追踪到了一个导入错误,并正在进行研究。